Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Selenium中使用getAttribute方法时获取无效Xpath错误_Xpath_Selenium - Fatal编程技术网

在Selenium中使用getAttribute方法时获取无效Xpath错误

在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(

使用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')]");