【问题标题】:get element via XPath with a variable in Karate通过 XPath 使用空手道中的变量获取元素
【发布时间】:2021-04-14 17:24:42
【问题描述】:

我想通过script() 函数获取一个元素,但我想使用我在 XPath 中定义的变量。知道这是如何工作的吗?

我使用的是空手道 1.0.1。

  * def username = __arg.username
  * print 'username:', username
  * def listRowElement = script("//div[@aria-colindex='1' and text()='"+username+"']", '_.textContent')
  * mouse().move(listRowElement).click()

如果我只输入用户名就可以了,但我希望它可以重复使用。

提前感谢您的意见。

【问题讨论】:

    标签: karate


    【解决方案1】:

    您不需要script() 来形成您的动态定位器,

    * def listRowElement = "//div[@aria-colindex='1' and text()='" + username + "']"
    * mouse().move(listRowElement).click()
    

    【讨论】:

    • 事实上这也可能有效:* mouse('{}' + username).click()
    猜你喜欢
    • 2020-08-14
    • 2021-02-13
    • 1970-01-01
    • 2015-09-02
    • 2019-08-24
    • 1970-01-01
    • 2020-07-19
    • 2015-04-02
    • 1970-01-01
    相关资源
    最近更新 更多