2013-03-04 90 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

相关问题