2013-04-25 249 views
1

我不明白这是怎么回事。错误有时会消失,但大部分是实际的。硒日志显示以下内容:Selenium服务器v2无法通过xpath找到元素“// html”

Element not found with xpath, //html 

Unable to locate element: {"method":"xpath","selector":"//html"} 
Command duration or timeout: 1.24 seconds 
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html 
Build info: version: '2.32.0', revision: '6c40c18', time: '2013-04-09 17:22:56' 
System info: os.name: 'Linux', os.arch: 'i386', os.version: '2.6.32-5-686', java.version: '1.7.0_11' 
Session ID: cbfc080e-f4a9-4ec9-aa72-3a8adeb0e9b9 
Driver info: org.openqa.selenium.firefox.FirefoxDriver 
Capabilities [{platform=LINUX, databaseEnabled=true, cssSelectorsEnabled=true, javascriptEnabled=true, acceptSslCerts=true, handlesAlerts=true, browserName=firefox, browserConnectionEnabled=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=17.0}] [] [] 

在此先感谢您的帮助!

UPDATE 我想通了,问题是只有实际的硒服务器的以下版本:

selenium-server-standalone-2.31.0.jar 
selenium-server-standalone-2.32.0.jar 

硒的服务器独立-2.28.0.jar正常工作与这样的XPath定位。

回答

0

两个想法:

  1. 尝试改变XPath来/html

  2. 尝试改变find方法来findElement(By.ByTagName("html"));

0

如果错误是间歇性的,是它可能是因为的webdriver试图在页面加载之前找到元素?如果你在那里坚持一个适当的等待,它是否摆脱了错误?

+0

这一点,而它最有可能揭示了问题的原因,应该是一个评论,不是答案。 – 2013-05-07 16:22:23

+0

是的,使用明确的等待可以解决问题。我认为在做任何动作之前等待页面加载应该是Selenium驱动程序的默认行为......我错了。 – 2013-08-09 08:54:53

0

我有同样的问题,我已修正这些随机误差,有两个动作:

  • 我已经添加了标签@insulated我所有的功能。它关闭每个场景的浏览器。您可以在Behat documentation上找到大多数信息。
  • 然后,当我执行Behat时,我添加了选项--rerun,因为在几个随机场景中我几乎没有随机错误。手册中有选项(./behat --help)。很快,你可以用这个选项执行behat:bin/behat [@NamespaceMyBundle[/myFeature.feature]] --rerun .behat_rerun。 (bin/behat,因为我在Symfony2项目中使用behat,并从顶层目录启动命令)。
  • 第三个选项我没有实现,但是在Behat doc上推荐的,是实现一个spin()方法,它将扫描并等待一个元素不可用。博客文章有here

enter image description here

相关问题