Groovy 脚本模式下的Katalon动态xpath

Groovy 脚本模式下的Katalon动态xpath,groovy,katalon-studio,Groovy,Katalon Studio,我想创建一个动态测试对象 下面是我的测试对象的xpath: (.//*[normalize-space(text()) and normalize-space(.)='${username}'])[1]/following::span[1] 我想在脚本中动态替换${username}。以下是我尝试过的: WebUI.verifyElementPresent(findTestObject('Page_CICIL_adminDashboard/span_Dash', [('username'):v

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

下面是我的测试对象的xpath:

(.//*[normalize-space(text()) and normalize-space(.)='${username}'])[1]/following::span[1]
我想在脚本中动态替换
${username}
。以下是我尝试过的:

WebUI.verifyElementPresent(findTestObject('Page_CICIL_adminDashboard/span_Dash', [('username'):varEmail]), 3)
但它抛出的
元素未找到
如下所示:

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}
变量未正确替换为my值。。你能建议一下如何正确操作吗?

我终于找到了一个(临时)解决方法: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)

您使用了哪种选项?-XPath-属性-CSS@TonyBui我正在使用xpath,这是一个已知的bug,我们正在修复它。同时,您可以使用属性:-单击属性-添加一个新项:“xpath”和您使用的值。@TonyBui啊,很高兴知道。。顺便说一句,我在下面的回答中找到了这个问题的临时解决方案:驻留,这是一个解决方法。。。我用这样的方法来定义大多数测试对象,因为我认为这是一种比使用对象存储库更好的方法。@MateMrše像这样对待所有测试对象更好吗?这就是我对待它们的方式,但我想这将取决于您的偏好。