verifyElementPresent & verifyElementNotPresent method

def winAddJob = 'Help Desk/winAddJob'

if (Windows.verifyElementPresent(findWindowsObject(winAddJob), 10)) {
	// Element is present; continue with your logic
	Windows.click(findWindowsObject('Help Desk/btnYesAddJob'))
	
	Windows.click(findWindowsObject('Help Desk/btnOKAddJob'))
} else {
	// Element is not present; handle accordingly
	WebUI.comment("Job is already added!")
}

Windows.click(findWindowsObject('Object Repository/Help Desk/pnMLV'))

I think my code is correct but I am getting an error instead of the method returning false.
Note: The actual window for winAddJob is not present, so the statement should return false.

Reason:
com.kms.katalon.core.exception.StepFailedException: Object ‘Object Repository/Help Desk/winAddJob’ is not present within 10 second(s)

Katalon version: 9.5.0
Build: 217

2 Likes

Hi there, :wave:

Thank you very much for your topic! It may take a little while before Katalon team member or others forum members respond to you.

In the meantime, you can double-check your post to see if you can add any extra information i.e. error logs, HTML codes, screenshots, etc. Check out this posting guide to help us help you better!

Thanks! :sunglasses:
Katalon Community team

Hi @xiencandido,

Welcome to our community. Thank you for sharing your issue with us. Looking forward to the support from experts here.

1 Like

I suppose you want the veryfyElementPresent() to return false without throwing an Exception. Then you should change your code :

1 Like

Thank you @kazurayam

But I cannot do a FailureHandling because if I’m not mistaken, it is an assert method, it would force the test case to fail. That is actually what I am trying to avoid in this scenario.

1 Like

How about this?

if (Windows.waitForElementPresent(findWindowsObject(winAddJob), 10, FailureHandling.CONTINUE_ON_FAILURE)) {

The waitFor* keywords won’t throw any Exception.

1 Like

The verify in itself is like an assert, and if you don’t specify the argument regarding the FailureHandling part, it will use the default failureHandling behavior (that is specified in the settings). You only overwrite this behaviour by specifying the failureHandling in the verifyElement’s argument.

The FailureHandling.OPTIONAL would not fail your test, only cause a warning on the test step, but not affect the test case’s final status, it can still be passed.

But the waitForElementPresent is a good alternative.

2 Likes

Thank you. This solved my problem.

Solution:

// Use the waitForElementPresent() instead of the verifyElementPresent() then add FailureHandling.OPTIONAL 

if (Windows.waitForElementPresent(findWindowsObject('Your Object'), 10, FailureHandling.OPTIONAL)) {
    // Element is present; continue with your logic
   WebUI.comment('Element present!')
} else {
    // Element is not present; handle accordingly
    WebUI.comment('Element not present!')
}
2 Likes

Hi @xiencandido,

It is great to hear that your problem has been solved. Can you please help mark the solution and explain how you solve it so that others can leverage it? Thank you!1

1 Like