Unable to use dynamic Xpath


I am trying to use below expression

findTestObject(‘//a[text() = ‘${sElement’}’)

here sElement is variable, I tried with and without single quotes but still unable to find object. If I use individual object it’s working fine. I tried similar Xpath with double quotes like below

findTestObject(“//a[text() = ${sElement}”), still it’s not working. I want to use dynamic Xpath. Please tell me how can we use dynamic Xpath

try it other way:

  1. define TO like : xpath = //a[text()=’${vString}’]
  2. in script use: findTestObject(TO,[(‘vString’) : sElement]))
    on the end you will have 1 universal definition for TO that can be called based on data you need to test

but to stick to your approach, in findTestObject you need to have path that applies in your ObjectRepository something similar to:
‘Object Repository/CC UI Pages/DataContainers Page/container_by_index’ and then you can try use double quotas and name of object in variable like:
“Object Repository/CC UI Pages/DataContainers Page/container_by_index_${elementIndex}”

also you can define TO on the fly read: https://docs.katalon.com/katalon-studio/tutorials/handling_static_dynamic_test_objects.html#introduction