How can I check if an element found using conditional statement?

Greetings!!!

Using this code below, I am trying to to check if an element finally found into a page but something is wrong here…

if (WebUI.verifyElementPresent(findTestObject('blah blah blah'), 2)) {
	println('Found')
} else {
	println('Not Found')
}
boolean check = WebUI.verifyElementPresent(findTestObject('blah blah blah'), 2)
if (check) {
	println('Found')
} else {
	println('Not Found')
}

If element exists I can see the Found word in console but if it doesn’t exist I just get an error instead of see Not found word!!!

Any idea why is this happening? What am I doing wrong?

Thank you for your time!!!

Please check the doc

verifyElementPresent() accepts 3rd argument FailureHandling, which is optional.

  • FailureHandling.STOP_ON_FAILURE
  • FailureHandling.CONTINUE_ON_FAILURE
  • FailureHandling.OPTIONAL

Your test case ran with STOP_ON_FAILURE, therefore your test immediately stopped.

You can change the default value of FailureHandling by the settings.

2 Likes

Thank you very much!!! Thank you for your time!!!