在 Workfusion 中,我迭代 HTML 页面中的所有元素,这些元素将由 xpath 找到:
//*[starts-with(@id,"FormView1_hidRevElement")][${i}]
当 ${i} = 1 时,我得到了预期的结果,但当 ${i} > 1 时却没有。
在 HTML 页面中,我有如下元素:
id="FormView1_hidRevElement12636"
id="FormView1_hidRevElement12637"
id="FormView1_hidRevElement12642"
等等,
抛出错误: ...
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: //*[starts-with(@id,"FormView1_hidRevElement")][2]
...
怎么了?
最佳答案
您创建的 XPath 是错误的,因为
//*[starts-with(@id,"FormView1_hidRevElement")]
将返回以下 id 的匹配计数为 3
id="FormView1_hidRevElement12636"
id="FormView1_hidRevElement12637"
id="FormView1_hidRevElement12642"
并且每个 id 匹配等于 1 那么显然 >1 条件将抛出错误,因为它不存在。
试试这个 XPath:
(//*[starts-with(@id,"FormView1_hidRevElement")])[${i}]
关于selenium - 无法通过 xpath 集合获取 Web 元素 (Workfusion),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54309664/