[WebUI] Verify Element Checked


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

When checkbox is not checked, show exception: StepFailedException and return false.

but all what I need to know is the checkbox is checked or not.
Please help

1 Like

hey, I got the same question now, have you solved this problem ?
Help guys !

+1, encountered the same issue. I just want to get the value and continue the next steps, but Katalon throws out the exception directly.
Is there any other way?

Here is the source code of the WebUI.verifyELementChecked

Please study this code to know what “WebUI.verifyWebElementChecked” keyword actually odes.

One way for you is to develop a custom keyword (namely “waitForElementChecked(TestObject, int timeout, FailureHandling)” that does nearly the same as WebUI.verifyElementChecked but does not throw StepFailedException in falsy case.

All you need to do is to comment out the Line#81.

               WebElement webElement = WebUIAbstractKeyword.findWebElement(to, timeOut)
               boolean isChecked = webElement.isSelected()
               if (!isChecked) {
                    // WebUIKeywordMain.stepFailed(MessageFormat.format(StringConstants.KW_MSG_OBJ_X_IS_NOT_CHECKED, to.getObjectId()), flowControl, null, true)
                    return false
                } else {

Another approach is possible.

You can use “WebUI.findWebElement(TestObject, timeout)” keyword in your Test Case script. You can get a hold of the HTML element you want to verify. So you can write your Test Case script as follows:

WebElement webElement = WebUI.verifyWebElement(....)
boolean isChecked = webElement.isSelected()
if (!isChecked) {
     // do whatever you want
}

No need to invent a custom keyword.