脚本模式下的 Katalon 动态 xpath

Katalon dynamic xpath on script mode

我想创建一个动态测试对象。

这是我的测试对象的 xpath:

(.//*[normalize-space(text()) and normalize-space(.)='${username}'])[1]/following::span[1]

我想在脚本中动态替换 ${username}。这是我尝试过的:

WebUI.verifyElementPresent(findTestObject('Page_CICIL_adminDashboard/span_Dash', [('username'):varEmail]), 3)

但它会像这样抛出 element not found

com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: 'Object Repository/Page_CICIL_adminDashboard/span_Dash' located by 'By.xpath: (.//*[normalize-space(text()) and normalize-space(.)='${username}'])[1]/following::span[1]' not found)

看起来 ${username} 变量没有被我的值正确替换。你能建议如何正确替换吗?

我终于找到了一个(临时)解决方法:D

我使用这样的脚本完全编写了 TestObject

String xpath_spanDash = "(.//*[normalize-space(text()) and normalize-space(.)='" + varEmail + "'])[1]/following::span[1]"
println '>>> the span dash xpath is: ' + xpath_spanDash
TestObject toSpanDash = new TestObject("span_Dash2")
toSpanDash.addProperty("xpath", ConditionType.EQUALS, xpath_spanDash)

并使用这种方式验证元素

// verifying elements
WebUI.verifyElementPresent(toSpanDash, 3)