private void select(WebDriver driver, String select_text) {
System.out.println("Selecting "+select_text+" from drop down menu");
Select select = new Select(driver.findElement(By.name("roomMenu")));
select.selectByVisibleText(select_text);
}
此功能在 Firefox 中运行良好,但在 IE 中运行时,它不会单击任何选项。对于 IE 有特定的方法吗?
编辑:
我在不使用 Select 对象的情况下重写了它,但它仍然拒绝单击该选项。
private void select(WebDriver driver, String select_text) {
System.out.println("Selecting "+select_text+" from drop down menu");
WebElement select = driver.findElement(By.name("roomMenu"));
List<WebElement> options = select.findElements(By.tagName("option"));
for (WebElement option : options) {
if (option.getText().equals(select_text)) {
System.out.println(option.getText());
option.click();
}
}
}
它打印出正确的选项,所以我知道它找到了正确的选项,但是当我执行 option.click() 时,IE 中没有任何反应。
最佳答案
我用-
private boolean selectFromDropDown(String locator, String value) {
try {
new Select(driver.findElement(By.xpath(locator))).selectByVisibleText(value);
return true;
}
catch (Exception e) {
verificationErrors.append(e.toString());
System.out.println("Could not find element");
return false;
}
}
在 IE 中也能正常工作! 从 here 获取.
关于selenium - 如何使用 webdriver 在 IE 中单击选择选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12921867/