If statement, execute only if first step was successful

Hey guys,

I’d like to use the if statement like "Only execute the follwoing steps if the first step was successful.

The code actually looks like this:

if(WebUI.click(findTestObject(‘Object Repository/Neue Fahrzeugauswahl/Page_/div_Fr welchen Betrieb soll der Deal angelegt werden_popupFormcontainerdealerinputa’))){

WebUI.click(findTestObject(‘Object Repository/Neue Fahrzeugauswahl/Page_/li_Daimler AG vertreten durch Mnchen22600’))

WebUI.delay(1)

WebUI.click(findTestObject(‘Object Repository/Neue Fahrzeugauswahl/Page_/span_Neuen Deal anlegen’))

}

When the first step (if condition) was not successful, Katalon skips the following steps, which is correct.
But so does Katalon when the if condition was successful…

Thanks so much for your help, I really don’t know what to do here.

what if you do this ? check if the element is clickable then click and do the all the steps

if(WebUI.verifyElementClickable(findTestObject(‘Object Repository/Neue Fahrzeugauswahl/Page_/div_Fr welchen Betrieb soll der Deal angelegt werden_popupFormcontainerdealerinputa’),FailureHandling.OPTIONAL)){

WebUI.click(findTestObject(‘Object Repository/Neue Fahrzeugauswahl/Page_/div_Fr welchen Betrieb soll der Deal angelegt werden_popupFormcontainerdealerinputa’))
WebUI.click(findTestObject(‘Object Repository/Neue Fahrzeugauswahl/Page_/li_Daimler AG vertreten durch Mnchen22600’))

WebUI.delay(1)

WebUI.click(findTestObject(‘Object Repository/Neue Fahrzeugauswahl/Page_/span_Neuen Deal anlegen’))

}
2 Likes

it’s because the WebUI.click function has no return value (void) so it’s always false

1 Like

In addition to @yoyox98’s solution, use FailureHandling.OPTIONAL as second parameter - otherwise test would fail if element not clickable.

if(WebUI.verifyElementClickable(findTestObject(‘Object Repository/Neue Fahrzeugauswahl/Page_/div_Fr welchen Betrieb soll der Deal angelegt werden_popupFormcontainerdealerinputa’), FailureHandling.OPTIONAL)) { ... }

2 Likes

Thank you! The test works now! :smile: