2013-04-25 387 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

相關問題