如何在Katalon Studio中编写动态定位器?

问题描述 投票:2回答:2

嗨,我在使用动态定位器时遇到问题。这是我的Xpath:// * [“@ id = row”+ $ {index} +“gridAlerts_AssignedToMe'] / div [4] / a”

Name: Xpath
Condition: Equals
Value: id("row${index}gridAlerts_AssignedToMe")/div[4]/a
Detect By Property: Check box is checked. 

这是我的脚本:

for (def index : (0..5)) {
def val = WebUI.getText(findTestObject('HomePage/AlertIdLocators', [('{index}') : index]))
}

我期望索引值应该在每次迭代时替换为0到5。

但它没有做..这是我的日志

11-30-2017 11:42:12 AM - [FAILED] - Test Cases/MyAlerts_LoopStatement FAILED because (of) Unable to get text of object 'Object Repository/HomePage/AlertIdLocators' (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: 'Object Repository/HomePage/AlertIdLocators' located by 'By.xpath: id("row${index}gridAlerts_AssignedToMe")/div[4]/a' not found)
katalon-studio
2个回答
3
投票

这里正确使用参数TestObject的示例:

int rowIndex = 1
TestObject myObject =   findTestObject('Object Repository/GENERICI/Tabella Risultati Ricerca GENERICA/voceDiAzione_byRow_byCol_byActionName',[('row'):rowIndex,('col'):8,('action'):'Elimina'])

TestObject定义enter image description here

在你的情况下,xpath值是这样的:id("row${index}gridAlerts_AssignedToMe")/div[4]/a


1
投票

在你的情况下,这不是一个正确的Xpath。最终的Xpath仍然没有将$ {index}变量解析成实际数字,因为你用双引号括起来,所以你的Xpath应该是这样的:

id("row$"+{index}+"gridAlerts_AssignedToMe")/div[4]/a
© www.soinside.com 2019 - 2024. All rights reserved.