【问题标题】:How use xPath in JS + WebdriverIO如何在 JS + WebdriverIO 中使用 xPath
【发布时间】:2018-05-25 17:13:33
【问题描述】:

我的 HTML 代码片段:

<span class="c-extselect__label js-label">Some text 1</span>
<span class="c-extselect__label js-label">Some text 2</span>

我想编写 xPath,点击其中一个跨度。

我知道这行得通:

browser.click(`//span[contains(text(), "Some text 1")]`); 

但我想根据“变量”点击一次“Some text 1”和嵌套时间将等于“Some text 2”。

我试过了:

browser.click(`//span[contains(text(), ${item})]`);

但它不起作用。

【问题讨论】:

  • 你可以试试://span[contains(text(), '${item}')]

标签: javascript xpath webdriver-io


【解决方案1】:

您需要在 ${item} 周围添加一个撇号以使 xPath 表达式有效://span[contains(text(), '${item}')]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-28
    • 2021-11-06
    • 2021-07-08
    • 2023-01-04
    • 1970-01-01
    • 2016-09-22
    相关资源
    最近更新 更多