Recorder if else statement

Help…
Can anyone help me out with how to use verifyElementchecked with if else statement

if (WebUI.VerifyElementChecked(findTestObject(‘Search_Enable/Page_nopCommerce administration/input_Enable Search_EnableSear’)) ==

true) {

WebUI.comment('Already enabled')

} else {

WebUI.click(findTestObject('Search\_Enable/Page\_nopCommerce administration/input\_Enable Search\_EnableSear'))



WebUI.comment('Now enabled')

}

It does not checks for the true the element in if and always run else part and script build error

Hi Arti, or i guess rather someone else who searches this topic

you chose the wrong categorie to post in… You should have chosen “Katalon Studio”::
But for completeness ill add what is the Problem here…
Maybe a Mod or Dev can change this if they will see it…

It’s needed to allow the WebUI Statements to Fail, to be able to use if else statements…
Here is what you will use for it:

For this you need to add this import:

import com.kms.katalon.core.model.FailureHandling as FailureHandling

And this will be you statements:

if (WebUI.VerifyElementChecked(findTestObject(‘Search_Enable/Page_nopCommerce 
administration/input_Enable Search_EnableSear’), FailureHandling.OPTIONAL) ==true) {

    WebUI.comment('Already enabled')

}else{

    WebUI.click(findTestObject('Search\_Enable/Page\_nopCommerceadministration/input\_Enable Search\_EnableSear'))

    WebUI.comment('Now enabled')
}

The “, FailureHandling.OPTIONAL” was missing. So everytime it would run through the if statement, the Statement WebUI.VerifyElementChecked would fail and cause an error. Which stops the execution of the Script.

Regards,
Chris