Currently I’m struggling with putting a variable into xpath to make the object detection dynamic.
The xpath which identifies the object(a_dashboarditems): //*[normalize-space(text())=‘Projects’] object.PNG
This works perfectly fine. I can adjust the name and it will also find other items
To make it dynamic, I made a variable on the variable tab called “dashboard”, with the default value: “Projects” variabletab.PNG
I modified the xpath value at the object in a few ways:
//[normalize-space(text(),${dashboard})]
//[normalize-space(text())=${dashboard}]
Unfortunately the options above don’t work, the object cannot be find and clicked on anymore.
As an extra step I want to make this variable tab using an excel sheet, but this easy once the step above is working.
Can someone point me into the right direction to make this work? A solution would also be nice.
Seems I cant edit my first post, but there’s a typo in the object.png screenshot: “projectbeheer” should be “projects” in the xpath.
The error message:
Test Cases/Test FAILED because (of) Unable to click on object ‘Object Repository/a_dashboarditems’ (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/a_dashboarditems’ located by ‘By.xpath: //*[normalize-space(text(),${dashboard})]’ not found)
But i can’t get it to work in the object’s property screen. I need to get this to work because i want to use a variable from a csvfile later on.
Anyone knows how to use the variable in xpath by using the objectproperty tab?
what I’m doing wrong? I tried the whole day, with css and with xpath property, but didn’t get this approach to work with Katalon Studio 5.4.2. As long as I use hard coded values for the active xpath statement of my TestObject (with Basic Selection Method) like:
//td[3]
or even for a accordingly css (Basic) statement like:
*:nth-of-type(3)>td
… everything is fine for a TestCase that accesses such TestObject in a way like:
The XPath Engine (jaxen built-in Katalon Studio) will evaluate the predicate [position()=‘3’] to false because ‘3’ is not a number. The function position() returns a number value. On the other hand, ‘3’ is a string. In XPath, a comparison of a number and a string makes false.
Then the above expression will result in the same value as
//td
XPath Engine offers 2 interpretation of this expression as follows:
a node-set of
elements in the HTML document
the 1st
element among a node-set of
elements in the HTML document
Katalon Studio takes the 2nd interpretation. Therefore you get the same value as “//td[1]”.
once again very conclusively deduced, thank you for your effort! But unfortunately, I had only forgotten to mention that, it doesn’t work for me without quotes either. The result of my command:
… in the case of using xpath is the same as with or without single quotes in the CSS statement:
[FAILED] - Unable to get text of object ‘Object Repository/myTestObject’ (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: …
It almost seems to me that my variable webElmId is empty? But the TestCase log even says at the beginning:
Variable 'webElmId' is set to 3 as default
BTW, is my expectation actually correct that I should be able to change this local variable to a different integer value during the TestCase runtime in order to use again and again:
Genius, that was my fault! I somehow assumed without checking that the object properties would have direct access to the (local) variables used in the respective TestCase. Thank you very much for illuminating that!
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
@kazurayam - Can you help me on this.
This is the xpath with value directly on it
//li[@id=‘Car’]
Trying to replace the above by
//li[@id=’${loanPurpose}’]
Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Page/auto’ located by ‘By.xpath: //li[@id=’${loanPurpose}’]’ not found
This is my xpath for table data: //tr[3]/td[3]/div
i need to write dynamic xpath . Could you please advise how i need to declare variable and how shall i code xpath .
I declared variable i =3 and j =3
and gave xpath like //tr[${i}]/td[${j}]/div but it didnt work. pls advise