Getting the xpath selector of a manually defined TestObject

I have defined a couple of Test Objects via some long XPath string. I know that you can get those TestObjects via findTestObject(pathToTestObject). I am now trying to get the XPath selectors that I defined manually, for use in test cases. How to do this?

Hi Michael,

what do you mean “XPath defined manually” ?

I mean thus:

I right-click “Object Repository”, New -> Test Object, select “XPath” radio button on the window that pops up, type the XPath in by hand, and click “Save”.

You should call the findPropetyValue(String) method of the com.kms.katalon.core.testobject.TestObject class

https://docs.katalon.com/javadoc/com/kms/katalon/core/testobject/TestObject.html#findPropertyValue(java.lang.String)

is 'xpath' the String argument to use here?

Yes, like this.

import com.kms.katalon.core.testobject.TestObject as TestObject
...
TestObject tobj = new TestObject('myTestObject')
String expr = '/some/valid/xpath/expression'
tobj.addProperty('xpath', ConditionType.EQUALS, expr)
WebUI.comment("xpath=${tobj.findPropertyValue('xpath')}")
1 Like