Passing non global variable into element xPath does not work

Please let us know what you are using Katalon Studio for?

I have currently applied Katalon Studio in my project

How would your work be affected if this issue has not been resolved?

  1. I cannot continue my job and have to work on something else while awaiting your response

Operating System

Windows 10

Katalon Studio Version

7.9.0

Katalon Studio logs

I have a test object named ‘button_instanceInfo’ and am trying to perform a simple click action onto that object, which is supposed to be a dynamic object:

My function is :

WebUI.click(findTestObject(‘Page_Self provisioning/button_instanceInfo’))

My object is defined by Xpath, as follows (this is a working example with global variable):

//td[@class=‘ng-binding’ and text()=’${GlobalVariable.T1InstanceName}’//…//td[@class=‘text-right’]//div[@class=‘btn-group btn-group-sm pull-right-flex dropdown’]//button[@ng-click=‘vm.showEditDialog(installation.ID)’]

If I run this line with object defined as above, the object is found and clicked on successfully.
However if I redefine my object as this:

//td[@class=‘ng-binding’ and text()=’${InstanceName}’//…//td[@class=‘text-right’]//div[@class=‘btn-group btn-group-sm pull-right-flex dropdown’]//button[@ng-click=‘vm.showEditDialog(installation.ID)’]

Even though I do have a variable for this test case named ‘InstanceName’ Katalon throws out the following error:

=============== ROOT CAUSE =====================
Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Page_Self provisioning/button_instanceInfo’ located by ‘//td[@class=‘ng-binding’ and text()=’${InstanceName}’//…//td[@class=‘text-right’]//div[@class=‘btn-group btn-group-sm pull-right-flex dropdown’]//button[@ng-click=‘vm.showEditDialog(installation.ID)’]

I have tried multiple options by changing qoute marks, etc, nothing works. Unless I am going to be defining a different object just to cover every single global variable, I do not have a workaround and this is an irritating issue.

You need to change your test case code as follows:

WebUI.click(findTestObject(‘Page_Self provisioning/button_instanceInfo’),
    ["instanceName": instanceName])

As the 2nd argument, you need to pass a list of name:value pairs. The name stands for the placeholder in the locator expression. The placeholder will be interpolated with the given value.