【发布时间】:2017-01-16 23:35:02
【问题描述】:
我正在使用 Java 和 Selenium 编写测试。我有一个下拉菜单,我需要从中选择一些东西。这是我的代码:
Select s= new Select(driver.findElement(By.xpath("blabla")));
s.selectByVisibleText("theName");
它适用于 Chrome 但在 Firefox 47 上我收到此错误:
org.openqa.selenium.ElementNotVisibleException:
Element is not currently visible and so may not be interacted with
我知道如何通过其他方式处理从下拉菜单中进行选择,但我需要使用Select 对象。
【问题讨论】:
-
您是否已验证 XPath 在 FF 上有效?没有相关的 HTML 就很难提供帮助。
-
那么您是否等到它使用
WebDriverWait变得可见?? -
试试 CSS 选择器而不是 xpath。 Coz xpath 可能在所有浏览器中都不相同。
-
@Jeffs 是的,FF 和 Chrome 的 xpath 是相同的,我们也使用了
wait.unit(...visibilityOfElementLocatedBy(..))
标签: java selenium selenium-webdriver selenium-chromedriver selenium-firefoxdriver