Search code examples
katalon-studio

How to write Dynamic locator in Katalon Studio?


I am having problem in using dynamic locator. Here is my 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. 

this is my script:

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

I am expecting the index value should be replaced by 0 to 5 on every iteration.

But this is not happening. Here is my Log

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)

Solution

  • here an example of correct use of parametric TestObject:

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

    The TestObject definition enter image description here

    In your case the xpath value is something like this: id("row${index}gridAlerts_AssignedToMe")/div[4]/a