我是 Selenium 新手,我遇到了一个问题,即下面的代码片段在通过 Chrome 驱动程序运行时抛出 NoElementFoundException,但在使用 Firefox 驱动程序时挂起。预期的行为是 Chrome 和 Firefox 都应该抛出异常。
我尝试将其嵌入到 try-catch 中,但 Firefox 上没有捕获到任何异常。我在互联网上搜索,但似乎找不到关于同一问题的其他帖子。
public static String getAlbumName(){
WebElement albumName = Browsers.getCurrentDriver().findElement(By.xpath("//div[contains(@class,...")));
String albumNameText = albumName.getText();
return albumNameText;
}
这是 Chrome 的异常: NoSuchElementException:找不到元素(警告:服务器未提供任何堆栈跟踪信息)
我使用的是 Selenium 2.25.0
知道为什么我会看到这种差异吗?
谢谢!
最佳答案
事实证明,这是 Selenium 中 Firefox 17 的一个已知错误,将在 Selenium 2.27 中修复 http://code.google.com/p/selenium/issues/detail?id=4814
降级到 Firefox 16 解决了我的问题。
关于java - Firefox WebDriver 在调用 findElement() 时不会抛出 NoElementFoundException 而是挂起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13997449/