使用selenium webdriver在firefox 48中选择下拉列表不起作用

时间:2016-09-16 16:05:26

标签: java selenium-webdriver selenium-firefoxdriver geckodriver

我正在使用Selenium 3.0和firefox 48来自动化应用程序。但是在firefox48中,自动选择下拉功能无效。

相同的代码适用于IE和Chrome。

浏览器或我的代码存在此问题吗?

enter image description here

Select sel = new Select(driver.findElement(By.xpath("//select[contains(@id,'BusinessUnit')]")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ctl00_vmsContent_rdwBusinessUnit_C_selBusinessUnit")));
List<WebElement> list = sel.getOptions();
for (WebElement el : list)
{
    System.out.println(el.getText());
    sel.selectByIndex(2);
}

1 个答案:

答案 0 :(得分:0)

我会简化代码。我添加了一些代码用于调试目的。

// wait until returns a WebElement, store it for later use
WebElement e = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//select[contains(@id,'BusinessUnit')]")));
// dump the HTML of the select element and make sure you have the element you are expecting
System.out.println(e.getAttribute("outerHTML"));
Select sel = new Select(e);
for (WebElement el : sel.getOptions())
{
    System.out.println(el.getText());
}
sel.selectByIndex(2); // pull this out of the loop or it will get selected mutliple times
// other options for selecting the desired OPTION
sel.selectByValue("12");
sel.selectByVisibleText("Engineering");