我在页面上有一个WebElements的定位器枚举列表。我希望能够使用枚举的组合以及我希望选择的选项的值的附加信息来选择选择框的特定选项。有没有办法做到这一点?我注意到By
类也有方法findElement(searchContext)
。我可以用这个作为沿着线的东西:Selenium:搜索Java中的定位器子项
public enum Dictionary {
TYPE (By.id("vehType")),
PROVINCE (By.id("provId")),
TERRITORY (By.id("territoryId")),
STAT_CODE (By.id("statCodeId")),
CLASS (By.id("class1Id"));
private final By locator;
private DetailVehicleDictionary (By value) {
this.locator = value;
}
public By getLocation() {
return this.locator;
}
}
然后,如果类是用HTML选择框:
<select id="class1Id" name="select_box">
<option value="1"/>
<option value="2"/>
<option value="3"/>
</select>
我可以做线沿线的东西:
WebElement specificValue = driver.findElement(Dictionary.CLASS.getLocation().findElement(By.cssSelector("option[value=2]"));
我需要访问实际元素,以便我可以等待DOM中存在的值。我打算在等待命令实现这个功能,比如:
wait.until(ExpectedConditions.presenceOfElementLocated(specificValue));
您可以在'findElement'的结果执行'findElement',但alec的解决方案更好。 – Richard 2015-02-06 18:21:07