Can You Help with Variable in web test object?

Hi everyone,

I’m new to automated testing and to Katalon Studio, so I apologize if this is a basic question:
I’m experiencing an issue with variables in XPath in Katalon Studio.
In my test case, I assigned the variable as a string with the value “KatalonTest2”. However, Katalon cannot locate the object when I use this variable format.
On the other hand, if I replace ${test123} directly with the static text “KatalonTest2” in the XPath expression then it finds the object successfully.

I’m attaching screenshots showing both situations: one with the variable that fails, and one with the static text that works.

Could anyone explain why this might be happening or offer any tips on using variables.
Thanks so much in advance!

1 Like

The characters in the screenshots are too small, hardly readable. Please provide readable ones.

Hello,
I’m currently using a Xiaomi 11T Pro, which has a 6.67-inch display, and with a certain level of zoom, I can read and see all the characters clearly.

OK

I don’t know how to see it. So I would quit.

could you please try to use the “li” tag as i see its a list. this may be creating a problem. also check whether there are any escaping characters.

I also tried using the “li” tag and have no escaping characters. Interestingly, this works in Katalon Recorder (the Chrome extension), but it doesn’t work in Katalon Studio.

Hi there, and thanks for posting in the Katalon community! :hugs:

To help you faster, please review our guide on Katalon Recorder here: Katalon Recorder overview | Katalon Docs. Double-checking the steps and configurations might resolve the issue.

If the doc doesn’t help, feel free to provide more details, and a community member will assist you soon. Thanks for being a part of our community!

Best,
Albert Le

can u use the li tag in your manually created xpath and check. I feel it would work

I already mentioned that I tried it, but it doesn’t work…

Make sure you have only 1 element found before you create your dynamic object. Your first screenshot shows that you found 2. This means your script will fail.

Hi, some resources you can check out:

  1. How to work with locators in Katalon Studio: https://academy.katalon.com/courses/creating-reliable-web-test-object-locators/
  2. How to parameterize value for test objects: https://academy.katalon.com/courses/parameterize-test-objects/

You also need to add the script variable to the script action that needs to use it.
Looking at your first screenshot the action that needs it is on row 10. Doubleclick on the li_KatalonTest2 object and add the script variable in the popup screen.
Like so: