How to create TestObject using Selection Method "Attributes"

Hello friends,

right now I’m trying to create a TestObject during Runtime.

I have a TestObject (Button) in my Repository that is working fine.

And its settings look like following:

So “Selection Method” is “Attributes” and Katalon automatically set the Properties:
type equals “button”
text equals “Submit”

Now I’m trying to reproduce this by code. But my problem is that I can not find any helpful documentation. There are plenty examples of using SelectionMethod “CSS”, “XPATH” … but found nothing about what I want to do:

I tried this:

TestObject makeTestObject(String buttonText) {
    TestObject testObject = new TestObject()
    testObject.addProperty("type", ContitionType.EQUALS, "button")
    testObject.addProperty("text", ContitionType.EQUALS, buttonText)
    return testObject

Here I couldn’t find a SelectionMethod called “Attributes”.
There is only “BASIC”, “CSS”, “IMAGE” and "XPATH.
So what exactly is “BASIC” (as this is no option in GUI-mode) and what do I have to choose, when I want to reach my goal?
This is quite confusing.

Running this got an error:

Any help would be wonderful. :slight_smile:

And before you ask why I don’t use the Xpath:
The Ids of the buttons in our WebApp changed way to often, and I don’t want to have to edit all the objects everytime this happens. So I realized Katalon always find’s a button when I just hand over the type and text, cause the text never changes (till now).

Thanks and have a nice day,

How about copying the Selected Locator from your image above and make it your TestObject’s xpath? And, personally, I might change the type to the tag.

testObject.addProperty("tag", ConditionType.EQUALS, "button")
testObject.addProperty("xpath", ConditionType.EQUALS, "//*[@type='button' and (text()='Submit' or . = 'Submit')]")

Also, you should add the appropriate import statements for the code (or maybe it’s because of your spelling of ConditionType)

import com.kms.katalon.core.testobject.ConditionType as ConditionType
import com.kms.katalon.core.testobject.TestObject as TestObject


You have a typo: ContitionTypeConditionType


Thank you both.

After solving that typo and finally importing ConditionType it worked like I first expected, without using xpath:

static TestObject makeButton(String buttonText) {
	TestObject testObject = new TestObject()
	testObject.addProperty("type", ConditionType.EQUALS, "button")
	testObject.addProperty("text", ConditionType.EQUALS, buttonText)
	return testObject

And about my first question concerning SelectorMethod:
I still don’t know what BASIC is, but if I need it, perhaps I will have a further look in the documentation if there is any.
And appearently, like you can see in my code you don’t need to specify the SelectorMethod.
I can just add the properties and it works.

Cause I’m always curious:


Whether I make an element in the Object Repository or code, I only use the two attributes: xpath and tag. Often, type is like a duplicate of tag and I am into simplicity (KISS).

	public static TestObject createTestObject(String tag, String xPathExpr) {
		TestObject tObj = new TestObject()
		tObj.addProperty("tag", ConditionType.EQUALS, tag)
		tObj.addProperty("xpath", ConditionType.EQUALS, xPathExpr)

		return tObj