How can I get the test object variable name using code?

I want to do something like that:

String testObjectName = findTestObject(‘Object Repository/salesforce/Leads/Save’).getName()

Is there a way that we can do something like that?

@jporras

By name, do you mean the name property of the web element that the Test Object points to ? or the ID of the Test Object. The ID of the Test Object can be retrieved:

String testObjectName = findTestObject(‘Object Repository/salesforce/Leads/Save’).getObjectId()

To get the name property of the web element you can use WebUI.getElementAttribute and pass in the Test Object.

Hi Katalon Developer,
For an unknown reason getElementAttribute is not present on my KSE version 7.6.2

What I need is get the Name of the test object:
findTestObject(‘Object Repository/salesforce/Leads/Save’)

println(testObjectName )

“Save”

It’s WebUI.getAttribute()

If you want the Test Object name, use the code @ThanhTo gave you.

println testObject.getName()

I think you guys can’t understand my question…
I have this test object created on my project:
findTestObject(‘Object Repository/salesforce/Leads/New’)

I need to get the string name “New”, I don’t need to get any css, tag property or such.

I want to know if Katalon support something like this:
String nameWebElement = findTestObject(‘Object Repository/salesforce/Leads/New’).getName()
println(nameWebElement)

On console:
“New”

testObjectName = findTestObject('Object Repository/GET user by id').getObjectId()

println testObjectName.split('/').last()

Output:

2020-09-30 11:31:12.104 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2020-09-30 11:31:12.107 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/New Test Case
2020-09-30 11:31:12.589 DEBUG testcase.New Test Case                   - 1: testObjectName = findTestObject("Object Repository/GET user by id").getObjectId()
2020-09-30 11:31:13.060 DEBUG testcase.New Test Case                   - 2: println(split("/").last())
GET user by id
2020-09-30 11:31:13.068 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/New Test Case
2 Likes