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.


2nd Dec 2021

I edited the code to fix my mistake

Hi kazurayam,

thanks for the response, sorry it has taken me a while, but your suggested solution does not appear to do the trick, I changed my code to pass in a variable as you suggested:

WebUI.click(findTestObject(‘Page_Self provisioning/button_instanceInfo’), [“InstanceName”: InstanceName])

error message:

=============== ROOT CAUSE =====================

For trouble shooting, please visit: https://docs.katalon.com/katalon-studio/docs/troubleshooting.html

12-02-2021 01:10:08 PM Test Cases/Working tests - do not change/All env -used with variables/Regression test 01 - 02. installation validation in customers NAV

Elapsed time: 39,545s

Test Cases/Working tests - do not change/All env -used with variables/Regression test 01 - 02. installation validation in customers NAV FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.click() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject, java.util.LinkedHashMap) values: [TestObject - ‘Object Repository/Page_Self provisioning/button_instanceInfo’, …]
Possible solutions: click(com.kms.katalon.core.testobject.TestObject), click(com.kms.katalon.core.testobject.TestObject, com.kms.katalon.core.model.FailureHandling), check(com.kms.katalon.core.testobject.TestObject), check(com.kms.katalon.core.testobject.TestObject, com.kms.katalon.core.model.FailureHandling), back(), wait()
at Regression test 01 - 02. installation validation in customers NAV.run(Regression test 01 - 02. installation validation in customers NAV:41)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:442)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:433)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:412)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:404)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:281)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:138)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:129)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1638443400974.run(TempTestCase1638443400974.groovy:25)

You have this now:

this is wrong.

You want:

WebUI.click(findTestObject('Page_Self provisioning/button_instanceInfo',
                           ["InstanceName": InstanceName]
                          )
           )

… ah, I found I wrote a wrong example. Sorry.

big thumbs up, thanks.
problem solved :slight_smile:

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.