Unable to retrieve xpath value from object repository object, why (part two)?

I wasn’t paying attention (not awake yet) for the answer on Unable to retrieve xpath value from object repository object, why?.

For that item, I realized (too late before question was closed) the the answer was not correct.

I need to be able to retrieve the xpath from the Object Repository itself, without finding the object on the page first. How do I retrieve the value of the item’s selection method (xpath in this case) directly from the object repository itself?

The Object Repository is just files on your disk. Read through the XML of the specific file and pick out the xpath.

alternate solution.
once a ‘test object’ or whatever else is instanciated, have some properties.
explore them.
it’s poo basics

I am trying to retrieve the properties from within a script execution (while that script is running) and have that xpath value stored into a variable, apologies for not making that clear.

The way I understood your concern is that the element was already in your Object Repository. And Katalon Studio supports Java and Groovy coding. The element in your Object Repository is just a file. Get the file, read through the file and either collect all the Key/Value pairs or only the BASIC one. Again, its only an idea of how it can be done, and it can be done as you are running a script. You just need to know some programming and some String manipulation methods. You can probably find most of this on Java / Groovy forums.




So there’s no variant of the GetProperty / GetAttribute to do this action natively?

Based on what you have above GetProperty should be working, but for me it’s returning NULL instead

I can assume that GetProperty or GetAttribute would work on the web page, not the OR. The xpath you may be trying to find is not “on the web page”, but an artifact that we create to “find” a pathway to the specific element on the web page. Saying that, there may be a number of other ways, but I’m not thinking of it or them yet: Inheritance, Web Element, Test Object inspect properties…

That’s why I was curious to see if there was a function that would allow the retrieval from the object repository element itself. Katalon has to do so in order to run the script, was hoping there was a function that users would be able to tap into

I would disagree with this. Your question was unclear, was not detailed enough.

You want to get a list of Test Object IDs from the Object Repository, right? Once you got the list of Test Object IDs, you can iterate over it to see if each Test Object has the XPath of your interest.

“Katalon Studio API” com.kms.katalon.core.testobject.ObjectRepository provides no method that returns a list of Test Objects contained.
Possibly Katalon developers have never imagined that users sometimes need to “refactor” the Object Repository. The "Recorder " tool tends to generated hundreds or thousands of Test Objects in the Object Repository, which includes a lot of entities unusable and a lot of duplications. Users need a way to find out rubbish Test Objects and clean them out. But Katalon Studio does not provide any feature of refatoring Test Objects. It’s a shame. Possibly Katalon developers never use the Recorder tool and Object Repository for their own sake. Software developers do not necessarily use their products.

How about me?
Well, I personaly rarely use Object Repository. I always construct TestObjects on the fly by code. Therefore I do not have any bulky TestObjects in the Object Repository folder.

So you need to develop a solution for yourself. Grasp the “Object Repository” folder in your project, and get the list of descendant .rs files as Test Objects. If you have layers of sub-folders, you need to visit them all. Possibly you want to study:

I am not sure on this.
For my understanding, the OP needs to retrieve the Selected Locator property (which may be an xpath) from the TO object … but I may be wrong also.

@kevin.jackey please bring more context, we are confused.

For my understanding, he needs to solve 2 steps of problems:

  1. the OP needs to get a list of Test Object IDs from the Object Repsitiory, first
  2. then secondly, he needs to iterate over the list entirely to select Test Objects that have the locator which matches his interest.

He needs to solve the first problem, then he would be able to go forward to the second. He can not skip the first.

Well, until the OP bring more context, I did a small experiment.
Based on his initial approach:

this_object = findTestObject('Object Repository/full_path')
my_xpath = this_object.findPropertyValue("xpath")
log.logInfo ('xpath property: ' + my_xpath)

I made a testobject like this (I am not sure if it is correct, I am not involved in web testing, is just to explore it)

and started to play with various methods documented in:

My testcase looks like this:

to = findTestObject('Object Repository/Sample Test Object')

println to.getClass()
println to.getProperties()

println to.getActiveXpaths()

println to.getXpaths()
println to.getXpaths()[0].value

I was expecting getProperties() or getActiveXpaths() to produce something, but are just empty lists.

2023-02-28 11:54:21.774 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2023-02-28 11:54:21.776 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/SampleTest Case
2023-02-28 11:54:22.158 DEBUG testcase.SampleTest Case                 - 1: to = findTestObject("Object Repository/Sample Test Object")
2023-02-28 11:54:22.210 DEBUG testcase.SampleTest Case                 - 2: println(to.getClass())
class com.kms.katalon.core.testobject.TestObject
2023-02-28 11:54:22.220 DEBUG testcase.SampleTest Case                 - 3: println(to.getProperties())
2023-02-28 11:54:22.222 DEBUG testcase.SampleTest Case                 - 4: println(to.getActiveXpaths())
2023-02-28 11:54:22.223 DEBUG testcase.SampleTest Case                 - 5: println(to.getXpaths())
2023-02-28 11:54:22.225 DEBUG testcase.SampleTest Case                 - 6: println(value)
2023-02-28 11:54:22.239 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/SampleTest Case

so looks like only getXpaths() produce a certain populated list, so I am confused.
Is my testobject wrong or the methods I tried are simply not working?

first guess will be, getProperties retrieves the settings under the Attributes tab, not the actual object properties.
must dig more.

@bionel - you are running into the exact problem I’m encountering, glad to see I’m not the only one :slight_smile:

Sorry, I don’t understand this. Any example?

Thanks for everyone looking into this!

Here’s the context: I have an element that appears on 90% of our pages, but has to be preceded in the xpath mapping by the specific instance of that element (i.e. - there can be more than one of these on the page, so I have to validate each one via a combination of (parent xpath) + (common object’s xpath).

I want to make this as easy to adjust and change in the future as possible, so I have the common element’s xpath stored in the script object repository, and was hoping to be able to retrieve that common xpath value so I could feed it into the (parent xpath) + (common object’s xpath) formula within a new TestObject, this way if the common object’s xpath characteristics (say the id property) were to change at any point in the future I only have to change it in one place instead of 30+ (this object is on a LOT of pages :slight_smile: ).

Thus in order to do this optimization, I need to be able to retrieve the xpath selector value directly from the object repository object. I’m new to Katalon, but have used QTP for almost a decade and was able to pull the object properties directly out of the object repository, so am attempting to duplicate this logic here and failing.

UPDATE: I could bury the common object xpath as a variable in an class file somewhere, but I figured it would be easier for others to find and manipulate if I had it in the object repository like everything else. As mentioned, this was fairly easy to do in QTP, so I was assuming it would be the same within Katalon as accessible by a GetXXXX type statement somehow.

I think I have already proposed a effective solution to this. Isn’t it enough?

Negative, as your query is pulling the xpath from an object on the page already, not from the object repository. You’re assuming that the object on the page can be found via the object repository item, when based on my example it cannot. @bionel is following the logic I need to resolve, in that they are attempting to pull the xpath information directly from the object repository.

Katalon has to be retrieving this information somehow as well, or the object repository wouldn’t work, I’m trying to figure out how Katalon is doing this and duplicate that methodology.


Here I quote a line from my code:

TestObject tObj = findTestObject('Object Repository/Page_CURA Healthcare Service/a_Make Appointment_BASIC')

Do you think that this line of query is pulling the xpath from an object on the page already, not from the object repository?

Here’s where things seem to be failing, though I misinterpreted what was going on above.

I run a modified version of your script :

TestObject tObj = findTestObject('Object Repository/Common Portal Elements/button_CommonTable_PageFullLeft')

String json = JsonOutput.toJson(tObj)
println json
println JsonOutput.prettyPrint(json)

String myreturn = tObj.getSelectorMethod().toString()
WebUI.comment ('Returned value 1: ' + myreturn)

myreturn = tObj.getSelectorCollection().toString()
WebUI.comment ('Returned value 2: ' + myreturn)

myreturn = tObj.getSelectorCollection().get(SelectorMethod.BASIC)
WebUI.comment ('Returned value 3: ' + myreturn)

with the following object repository:

and get the following log replies:


Do you know that you can create Test Object dynamically by code at runtime? You need not to prepare Test Object in the Object Repository.