【问题标题】:How do you click a select option in IE with webdriver?如何使用 webdriver 在 IE 中单击选择选项?
【发布时间】:2012-10-06 23:25:30
【问题描述】:
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 中没有任何反应。

【问题讨论】:

    标签: selenium webdriver selenium-webdriver


    【解决方案1】:

    我用-

    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得到它。

    【讨论】:

      猜你喜欢
      • 2017-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-07
      • 2015-06-23
      • 2015-06-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多