Retrieving and xPath name from a TestObject loaded into memory

Hey ya’ll, for my project I need to extract every xPath from a TestObject within my repository, alter it, and slam the new xPaths into a TestObject that lives in memory. Here’s where I’m getting stuck. Code tho:

TestObject to = findTestObject(ObjectID)
to.findXpathValue(‘xpath:link’) // This gets exactly what I need, but I need to ‘know’ the name before hand
to.getXpaths()

Ideally, I’d like to retrieve the xpaths, but I need to know the names of associated with them – unfortunately the last foo gives me this when I print:

[com.kms.katalon.core.testobject.TestObjectXpath@c2db68f, com.kms.katalon.core.testobject.TestObjectXpath@3cc41abc, …]

Is there any way to ‘turn’ this data back into names so I can retrieve the xPaths? .findProperties() gets me something similar as well. Cheers!

Got it. Didn’t realize that the xPaths were an object. Throwing this on the end is the solution!

import com.kms.katalon.core.testobject.TestObjectXpath

List xpathList = to.getXpaths()

for( i in 0…xpathList.size()-1){

println(xpathList[i].getName())

}

1 Like

Thank you for sharing this with our community @joel.scott :100:

Cheers, technically the solution above isn’t correct. Replace the line:

println(xpathList[i].getName())

With:

println(xpathList[i].getValue()

Idk, I’m the ‘Kata/selenium’ guy on the team and was trying to create a keyword that handles transforming a stored test object to a dynamic one to make it easier for others to write dynamic test cases :slight_smile: