脚本模式下的Katalon动态xpath

时间:2019-01-10 17:49:18

标签: groovy katalon-studio

我想创建一个动态测试对象。<​​/ p>

这是我的测试对象的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}变量没有正确地替换为我的值。.您能建议如何正确地设置它吗?

1 个答案:

答案 0 :(得分:1)

我终于找到了这个: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)