为了账号安全,请及时绑定邮箱和手机立即绑定

硒 | NamespaceError:无法在“文档”上执行“评估” | 包含不可解析的命名空间

硒 | NamespaceError:无法在“文档”上执行“评估” | 包含不可解析的命名空间

一只斗牛犬 2022-11-30 14:28:34
我可以使用浏览器的开发人员工具检查元素,如下所示:使用 FireFox 检查元素:/html/body/div[1]/div/div[8]/form/div[2]/spring:eval/table/tbody/tr[2]/td[5]使用 Chrome 检查相同的元素,如下所示://*[@id="searchVO"]/div[2]/spring:eval/table/tbody/tr[2]/td[5]但是,当我尝试在脚本中使用这些 XPath 中的任何一个时,执行失败并显示以下堆栈跟踪:WebElement formElement = wd.findElement(By.xpath("//*[@id=\"searchVO\"]/div[2]/spring:eval/table/tbody/tr[2]/td[5]"));或者WebElement formElement = wd.findElement(By.xpath("/html/body/div[1]/div/div[8]/form/div[2]/spring:eval/table/tbody/tr[2]/td[5]"));堆栈跟踪:org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //*[@id="searchVO"]/div[2]/spring:eval/table/tbody/tr[2]/td[5] because of the following error:NamespaceError: Failed to execute 'evaluate' on 'Document': The string '//*[@id="searchVO"]/div[2]/spring:eval/table/tbody/tr[2]/td[5]' contains unresolvable namespaces.………*** Element info: {Using=xpath, value=//*[@id="searchVO"]/div[2]/spring:eval/table/tbody/tr[2]/td[5]}    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)    at java.lang.reflect.Constructor.newInstance(Unknown Source)    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)我也确认网页上没有Frames;然而,上面的元素存在于一个表单中——下面给出了这个元素的片段——我试图找到下面的状态“Operative”或“Stopped”——上面的 Xpath 属于这个状态字段。在进行此搜索后,如果状态为“Operative”,则我需要单击 Product1。
查看完整描述

2 回答

?
慕森卡

TA贡献1806条经验 获得超8个赞

这是操作的 xpath。

WebElement formElement = wd.findElement(By.xpath("//div[@id='nc-bd']/following-sibling::div[1]//table//tr[2]//td[5]"));

和 xpath 停止。

WebElement formElement = wd.findElement(By.xpath("//div[@id='nc-bd']/following-sibling::div[1]//table//tr[3]//td[5]"));


查看完整回答
反对 回复 2022-11-30
?
Helenr

TA贡献1780条经验 获得超3个赞

这是将标识所有产品的 xpath Operative

//form[@id='searchVO']//table//tr[td[normalize-space(.)='Operative']]/td[count(./ancestor::table//tr[1]/th[normalize-space(.)='Product'])+1]



查看完整回答
反对 回复 2022-11-30
  • 2 回答
  • 0 关注
  • 90 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信