selenium - 无法通过 xpath 集合获取 Web 元素 (Workfusion)

标签 selenium xpath rpa workfusion

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

相关文章:

xml - 如何使用 XSLT 1.0 查找 XML 节点的存在

xpath - 在使用 concat 的 Xpath 1.0 和 2.0 表达式中需要帮助

python - 在Python、Selenium Webdriver中提取<a>内容

java - 在使用 Cucumber 和 JUnit 时,如何截取屏幕截图并将其附加到 Allure 报告中?

java - 我们在哪里使用这个Constructor RemoteWebDriver(java.net.URL remoteAddress, CapativitydesiredCapabilties, Capativity requiredCapativity)

java - 无法使用 Selenium(Java、Chrome WebDriver)单击按钮

rpa - UIpath机器人管理器

python - WebdriverWait 显示 TimeoutException,如果我使用 sleep.time 它工作正常

python - NoSuchElementException : Message: Unable to locate element while trying to click on the button VISA through Selenium and Python

selenium - 在 RPA Express 中使用 Web 元素处理和跟踪链接