Problems when using a variable obtained from an external spreadsheet (data-driven) to use as an object property

I’m trying to use a variable (from an external spreadsheet) to determine a page object to click, that will vary with each data-driven iteration.

My test object can be identified (non-data-driven) using the following object properties (using ‘Attributes’ as the selection method):

xpath | equals | //*[@id="radio-button1"]

I’m then creating a variable called button1, so that my test object ultimately looks like this:

xpath | equals | //*[@id="${button1}"]

And of course, the value of variable button1 in my spreadsheet is ‘radio-button1’ (also note that I’ve just just using id = …).

However, the object is not being recognised. I see an error similar to the following:

Unable to click on object 'Object Repository/Page_My Page/My Radio Button 1' (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: 'Object Repository/Page_My Page/My Radio Button 1' located by 'By.xpath: //*[@id = '${button1}']' not found)

Although I’ve used various forum posts as a guide to achieving this, I suspect I’ve misunderstood how this works. Might someone be able to enlighten me please (in as simple terms as possible, for a non-programmer, please)?

Thanks :slight_smile:

provided your variable it is declared in the test-case ‘Variables’ tab (not locally inside the script), now you have to add your test-case to a test-suite.
Use the ‘Data Binding’ from the top right to assign your test data to the suite, and map the right variable from the test data to the right one in the test-case. If both have same name, you can use the ‘map all’ feature, otherwise you have to bind them manually


Thanks Ibus.

Sorry - I should’ve made clearer that all other aspects of data-driven aspects are working fine - I have the variable declared in the test case, and have the data-binding correctly setup for the test suite, and corresponding mappings.

I generally use data-driven to vary in the inputs - e.g. things like usernames, passwords, URLs, that vary from iteration to iteration - and this is all working fine.

It’s this particular aspect of trying to use a variable to define an object that I’m having difficult with.


aaah … ok.
You have to build your test-object dynamically I think straight from the script. See:

Thanks - this certainly looks worth a go and I will indeed give it a go, though I’m still concerned I’ll end up in the same boat, as ultimately I still need the object ID to come from a variable.

In the meantime, if anyone has any suggestions for how I can rectify the manner in which I attempted it in the first place, that would be very much appreciated :slight_smile:

So the first problem I come accross here is that the object isn’t found (despite the log suggesting it’s got the correct ID), and I strongly suspect this is because the object has a parent iframe, which I don’t know how to incorporate into the following (from the linked URL above):

String dynamicId = 'Katalon123'
String xpath = '//div[@id="' + dynamicId + '"]'
TestObject to = new TestObject("objectName")
to.addProperty("xpath", ConditionType.EQUALS, xpath)

I think the above script is working correctly (not that I’ve yet incorporated my data-driven variable into this yet), but I think the parent iframe has to be included somehow, I’d presume.

So, it looks like I’m back to square one (i.e. preferring to use an existing object, so I can easily specify parent iframe) unless anyone knows how to specify the parent iframe with the above script?


Hi @Kevin_McAndrew1

Katalon API Doc provides a method setParentObject(TestObject to) which takes in a TestObject, is this what you’re looking for ?

Regards !


You need to pass the variable to the test object and you can do this in two ways:

  1. In Manual mode when you select the test object from the list of objects from object repository, on the bottom side of the window you can set the variables that you can pass to the test object. You need to click add, param type: string, param: button1, value type: variable, value: select from dropdown the variable defined in your test case (button1).
  2. From script:’ Page_My Page/My Radio Button 1', [(‘button1’) : button1]))

Hope this helps.

ThanhTo, thanks for your response, but I think this is a little beyond me; I’m sure all the info is there, but as stated I’m not a developer.

cristian.ivanescu - thank you! I followed your instructions for 1. Manual Mode, and it worked. I was aware that I needed to pass the variable to the test object, and where to do this, but I wasn’t aware of how to configure this aspect - your description of exactly what to put, and where, was very clear and it worked straight away!

Thanks to all those who’ve responded :slight_smile: