2013-03-04 25 views
0

我在使用getAttribute方法時出現無效的xpath錯誤...雖然我能夠在firepath中使用相同的xpath來定位圖像。在Selenium中使用getAttribute方法時出現無效的Xpath錯誤

我使用以下方法..

字符串imgAtt = StartServer.browser.getAttribute( 「// IMG [含有(@ ALT, '硒IDE標誌')]」);

錯誤:在螺紋

異常 「主」 com.thoughtworks.selenium.SeleniumException:錯誤:無效的xpath [2]:// IMG [含有( 在com.thoughtworks.selenium.HttpCommandProcessor。 throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:112)

回答

0

也許你需要使用fn:contains

String imgAtt = StartServer.browser.getAttribute("//img[fn:contains(@alt,'Selenium IDE Logo')]"); 

或宣佈默認函數N amespace。但是我對Selenium不太瞭解,告訴你如何做到這一點。

此外,您在getAttribute中調用的XPath不會返回屬性。它將是一個<img>元素。由於參數類型無效,函數可能會引發異常。如果你只想要屬性,使用方法:

String imgAtt = StartServer.browser.getAttribute("//img/@alt[contains(.,'Selenium IDE Logo')]"); 
+0

你能在上面的語句更新我的XPath ......我沒有得到你......當然 – Paras 2013-03-04 19:39:06

+0

@pArAs,看看更新的答案。 – wst 2013-03-04 19:44:22

相關問題