【问题标题】:Select drop down is not working in firefox 48 using selenium webdriver使用 selenium webdriver 选择下拉菜单在 Firefox 48 中不起作用
【发布时间】:2016-09-16 16:05:25
【问题描述】:

我正在使用 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);
}

【问题讨论】:

标签: java selenium-webdriver selenium-firefoxdriver geckodriver


【解决方案1】:

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

// 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");

【讨论】:

  • 你有什么解决办法吗?
  • @HemaSundar 当然,在我上面的回答中。我很困惑你在问什么。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-29
  • 2015-02-15
  • 1970-01-01
  • 2015-01-18
相关资源
最近更新 更多