[WebUI] Click

This is a companion discussion topic for the original entry at https://docs.katalon.com/katalon-studio/docs/webui-click.html

is it possible to create a test object to save the initial test object in it and then interact with it? I can’t get this to work

For example:

WebElement MyTestObject1 = WebUiCommonHelper.findWebElement(findTestObject(‘Object Repository/SomeTestObject’), 30)


Try “TestObject” not “WebElement”.

TestObject MyTestObject1 = findTestObject(‘Object Repository/SomeTestObject’)

Yes, thank you. I figured out I was wrong shortly after I posted :slight_smile:

why the Click command is running for a very long time? Command execution time-Elapsed time: 30,262 s

click(findTestObject(“Object Repository/Distributors/Booking/button_Select”), OPTIONAL)

Elapsed time: 30,262s
changing object properties from attributes to xpath doesn’t help

It likely means that your default timeout period is 30 seconds and that the click event did not find the button element. Review your button element’s xpath or whichever means you used to locate it (and if you use multiple references to locate your button element, like class, style, width, etc., then perhaps reduce to just having tag and xpath selected).

Thank you, but the fact is that in the end the command is executed and the button is pressed, but it takes 30 seconds. I can’t use Xpath because it is changing.
The command is also processed for a long time -
selectOptionByValue(findTestObject(“Object Repository/Distributors/Booking/button_Select”), “1”, false, OPTIONAL)

Elapsed time: 1m - 0,363s

What is the tag for the element, button_Select?

selectOptionByValue(findTestObject(“Object Repository/Distributors/Booking/button_Select”), “1”, false, OPTIONAL)

selectOptionByValue, selectOptionByLabel and selectOptionByIndex only work on a select tag.

hi, this is tag;

Why does the “click” command take so long? Where can I change the timeout to 2 seconds?

Are you moving to a different web page between clicking on your “Log_in” button and your “GoToRPIE” button?

Being on the page https:site/auth/login, I click on the “Log_in” button, go to the page https://site/taxappeal/ there appears a pop-up and in it I click on the “GoToRPIE” button

then your test case script MUST wait for the the page https://site/taxappeal/ is loaded completely and a popup is displayed before your script tries to click on the “GoToRPIE” button.

Your current script calls a WebUI.click("Log_in button") and soon (in just a few milli-seconds) calls WebUI.click(GoToRPIE button) without waiting for the pop up is ready to click. The second call WebUI.click() failed because the pop up is not yet there in a few milli-seconds.

The second “click” failed instantly. But the failure was reported after 30 seconds of timeout. — I think this behaviour is not good.

Thanks for the answer. It turns out that it was necessary in the execution - the “Default Smart Wait” was set to enable:

It’s ok to use the Smart Wait if it solves your current problem.

But the Smart Wait is NOT necessary. It is a magic spell, that may help sometimes, but not always.

I would advise you not to rely on it. Rather you should learn/find how to code an appropriate “wait” for yourself. The magical Smart Wait tends to leave you untrained.

Got it, thanks!

Is its possible create an object and after create it, to do a click

example on webdriver:
DesiredCapabilities btn_next =new DesiredCapabilities()
btn_next.setCapability(“id”, ‘next-btn’)
btn_next.setCapability(“type”, ‘submit’)
btn_next.setCapability(“text”, ‘Next’)


this example is possible i have errors when i tried

Assuming you are using Katalon Studio, I have been able to do it with something like below:

import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.testobject.ConditionType as ConditionType
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

"xpath to the next button"
xpath = '//button[text()="Next"]'     // or id("next-btn")
"make a test object in code"
TestObject tObj = new TestObject(xpath)
tObj.addProperty("xpath", ConditionType.EQUALS, xpath)
"click on the Next button"
1 Like

I’m trying to cause a WebElementNotFoundException.

TestObject loginButton = findTestObject('Object Repository/Page_Zack Market/input_Password_button_btn__2lzmo')
WebUI.click(loginButton, FailureHandling.STOP_ON_FAILURE)

The TestObject is found. click complains with

Unable to find the element located by 'By.xpath: foo'. Please recheck the objects properties to make sure the desired element is located. 

where I’ve deliberated given a bad XPath. The step fails to fail. The automation fails to stop. Worse yet

04-20-2022 03:33:37 PM click(loginButton, STOP_ON_FAILURE)

Elapsed time: 31.439s

Object: 'Object Repository/Page_Zack Market/input_Password_button_btn__2lzmo' is clicked on

How was the button clicked if it couldn’t be found?

1 Like

Just a couple of points first if you don’t mind. Note that a WebElement and a TestObject are not the same, although both use xpath to find the element.

Note you can shorten your script by “inserting” the “findTestObject” into the TO position of the click() method, as long as you have the proper import statement at the top of the test script.

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

WebUI.click(findTestObject('Object Repository/Page_Zack Market/input_Password_button_btn__2lzmo'), FailureHandling.STOP_ON_FAILURE)

If you go with Selenium in your test script, then you can get WebElements, but if you don’t have the pathway within a try–catch, then the exception causes the browser to close. This is prevented if you are using TestObjects.

import org.openqa.selenium.WebElement as WebElement
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory

def driver = DriverFactory.getWebDriver();

WebElement button = driver.findElement(By.xpath('//button[@text="Password"]'));

Do you only have an xpath for your element (and maybe a tag) and nothing else? My thinking is that your element is being “found” by other means than just the xpath.

1 Like