在Selenium中使用getAttribute方法时获取无效Xpath错误
使用getAttribute方法时出现无效的xpath错误。。。尽管我能够在firepath中使用相同的xpath定位图像 我正在使用下面的方法 字符串imgAtt=StartServer.browser.getAttribute(//img[contains(@alt,'Selenium IDE Logo')]) 错误: 线程“main”com.thoughtworks.selenium.SeleniumException中出现异常:错误:无效xpath[2]://img[contains(在Selenium中使用getAttribute方法时获取无效Xpath错误,xpath,selenium,Xpath,Selenium,使用getAttribute方法时出现无效的xpath错误。。。尽管我能够在firepath中使用相同的xpath定位图像 我正在使用下面的方法 字符串imgAtt=StartServer.browser.getAttribute(//img[contains(@alt,'Selenium IDE Logo')]) 错误: 线程“main”com.thoughtworks.selenium.SeleniumException中出现异常:错误:无效xpath[2]://img[contains(
在com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:112)也许您需要使用
fn:contains
:
String imgAtt = StartServer.browser.getAttribute("//img[fn:contains(@alt,'Selenium IDE Logo')]");
或者声明默认的函数名称空间。但是我对Selenium不够熟悉,无法告诉您如何做
另外,在getAttribute
中调用的XPath不会返回属性。它将是
元素。可能是由于参数类型无效,函数引发异常。如果只需要属性,请使用:
String imgAtt = StartServer.browser.getAttribute("//img/@alt[contains(.,'Selenium IDE Logo')]");