selenium - 如何使用 webdriver 在 IE 中单击选择选项?

标签 selenium webdriver selenium-webdriver

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/

相关文章:

python - Scrapy with selenium, webdriver 无法实例化

java - Webdriver:为什么我仍然得到 'Unexpected Alert Open'?

webdriver - 如何在 Selenium Webdriver 中移动光标

.net - Internet Explorer 保护模式错误

python - 如何解决 PyTest 中的陈旧元素异常

ruby - 无法在 firefox 17 上运行 selenium 套件

C# OpenQA 和 OperaDriver() 问题。 selenium OpenQA v2.5 没有 Opera

c# - 截图后 PhantomJS 巨大的内存消耗

php - PHPUnit和 header 被发送

python - 如何使用 selenium TouchActions python 点击​​特定元素内部的坐标?