Interacting with dynamic xpaths

Morning All,

I have a requirement to interact with an element who’s xpath will not be known until we run the test and therefore can’t be stored as an object (to the best of my knowledge).

For context, imagine a screen grid showing rows of data and each row has a edit or delete button (to delete or edit that row).

I need to click on the delete or edit button against a specific record I will have added earlier in the test

So the target element xpath would be in a template but the text used as an initial anchor to identify the target row would be a variable, i.e. random string generated earlier in the test.

Imagine the xpath //span[text()={variable}] and you want to for example verify element present.

Has anyone been able to do this? Is this a supported feature of Katalon Studio?

what you need is already part of Katalon features. You can define TestObject with varable inside taht will be set when test is runing:

call in script:

1 Like

Hi, thanks for the replay and glad to see this is looking promising.

To just keep things initially simple then I am trying this on input fields that all have a different attribute of type

So an object InputField is defined as such:


Then to enter text in the field with the Type=password I am doing the following:

WebUI.setText(findTestObject(‘work in progress/Login test using variable/Field using variable’), ‘SomeData1’,[(‘FieldType’):‘password’])

This doesn’t work with the following snippet of the error:
Test Cases/98.Work in progress/objects with variables FAILED.
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.setText() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject, java.lang.String, java.util.LinkedHashMap) values:

Any thoughts??

  findTestObject("work in progress/Login test using variable/Field using variable",[("FieldType"):"password"]), 

parameters are part of findTestObject() fn:

1 Like

Still not work, so first thing - it looks like in the example above I am setting the object correct then, so the issue is way I am using it in the call.

I’m trying another example mirroring yours with the click.

Login button can be defined as //button[@type=‘submit’], so I am setting as follows with the variable


Then to click the button I have:‘path-to-object’,[(‘Variable’):‘submit’]))

So I believe what you have in the example, but not working .

any errors?
are you sure that there is only 1 object type = button with attribute type = submit?

1 Like

Right, I feel a right dumbass :smiley:

For the click example I didn’t have the little checkbox ticked to select the attribute for use in the selection - once ticked this worked as expected. (I don’t typicall use attributes, I tend to use xpath)

I’m now going to try the text entry one now and put the variable declaration in the right spot - I’ll report back

PS - So far, thanks for the assistance on this.

1 Like

I tried this again and worked a treat.

It’s my first time posting on this forum, so really appreciate the assistance.

1 Like

any time :slight_smile:

1 Like