# IF ELSE statements in Katalon

**URL:** <https://forum.katalon.com/t/if-else-statements-in-katalon/28297>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [June 20, 2019, 9:38am UTC](https://forum.katalon.com/t/if-else-statements-in-katalon/28297 "2019-06-20T09:38:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anjanaiv.26](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@anjanaiv.26](https://forum.katalon.com/u/anjanaiv.26)\
**Post date:** [June 20, 2019, 9:38am UTC](https://forum.katalon.com/t/if-else-statements-in-katalon/28297/1 "2019-06-20T09:38:32Z")

</div>

Hi All,  
I find it weird when Katalon execute IF ELSE statements  
I have simple IF statement, if the panel element is not present click an element to make that panel element present, if it is already present do not click  
if(WebUI.verifyElementNotPresent(findTestObject(‘Page\_SurveyQuestions/span\_SurveyPanel’),30)){  
WebUI.doubleClick(findTestObject(‘Page\_SurveyQuestions/span\_Screening’))  
}  
If the element is not Present it works perfectly, but if it does present, I just wanna it goto next statement without any action, but it fails with below exceptions:

Unable to verify object ‘Object Repository/Page\_SurveyQuestions/span\_SurveyPanel’ is not present  
Web element with id: ‘Object Repository/Page\_SurveyQuestions/span\_SurveyPanel’ located by ‘By.xpath: //mat-expansion-panel[contains(@class,‘survey-panel’)]’ is present after ‘30’ second(s)

---

<div class="post-metadata">

**Author:** ![hpulsford](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/hpulsford/32/2985_2.png) [@hpulsford](https://forum.katalon.com/u/hpulsford)\
**Post date:** [June 20, 2019, 10:10am UTC](https://forum.katalon.com/t/if-else-statements-in-katalon/28297/2 "2019-06-20T10:10:14Z")

</div>

> [@anjanaiv.26](#):
>
> I find it weird when Katalon execute IF ELSE statements

Katalon executes if statements like any other program would. Its most likely down to the way you have written it. Please share your whole if statement including the else so i can take a look. It should look something like this. Although reading the error message tells me that you might not have an else part which is what will be causing your problem

if(WebUI.verifyElementNotPresent(findTestObject(‘Page\_SurveyQuestions/span\_SurveyPanel’),30))  
{  
WebUI.doubleClick(findTestObject(‘Page\_SurveyQuestions/span\_Screening’))  
}  
Else  
{  
//do what ever you want it to do if its present.  
}

---

<div class="post-metadata">

**Author:** ![anjanaiv.26](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@anjanaiv.26](https://forum.katalon.com/u/anjanaiv.26)\
**Post date:** [June 20, 2019, 10:32am UTC](https://forum.katalon.com/t/if-else-statements-in-katalon/28297/3 "2019-06-20T10:32:27Z")

</div>

@ hpulsford]([http://forum.katalon.com/u/hpulsford](http://forum.katalon.com/u/hpulsford))  
Thanks for your response  
I didn’t know ELSE is mandatory for IF statement, if condition is true executes otherwise if would move to next statement is what is my understanding  
Anyways I did add ELSE per your suggestion I get the same error still.  
if(WebUI.verifyElementNotPresent(findTestObject(‘Page\_SurveyQuestions/span\_SurveyPanel’),30)){  
WebUI.doubleClick(findTestObject(‘Page\_SurveyQuestions/span\_Screening’))  
CustomKeywords.‘custom.affectlabHandlers.selectTestPanel’(‘Add Screening Questions’)  
}else{  
CustomKeywords.‘custom.affectlabHandlers.selectTestPanel’(‘Add Screening Questions’)  
}

It is failing at verify statement, verify doesn’t return FALSE if the element is present.

---

<div class="post-metadata">

**Author:** ![Arnel](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/arnel/32/6360_2.png) [@Arnel](https://forum.katalon.com/u/Arnel)\
**Post date:** [June 20, 2019, 10:57am UTC](https://forum.katalon.com/t/if-else-statements-in-katalon/28297/4 "2019-06-20T10:57:17Z")

</div>

Hi Anjanaiv,

I don’t think your if else statement is the one to blame here.

As Harry said:

> [@hpulsford](#):
>
> Katalon executes if statements like any other program would

katalon team will not change any logic here.

Based on my understanding, there’s a difference between:

```auto
verifyElementPresent
And
verifyElementVisible

..... or any methods related to those two, such as:
verifyElementNotPresent
verifyElementNotVisible
etc. . . . .

```

That’s why those two methods are created.

Someone correct me if I’m wrong, this is based on my experience using these two ----  
VerifyElementPresent deals with the source (HTML) means it maybe present in the in the source but not visible on the website while VerifyElementVisible deals with the UI itself.

And, there’s nothing wrong about katalon if else statement. Possibly your condition is the one to look out for.

My suggestion is try to observe and use “Visible”. Maybe that will do the trick.

Hope that helps. . . 🙂

---

<div class="post-metadata">

**Author:** ![anjanaiv.26](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@anjanaiv.26](https://forum.katalon.com/u/anjanaiv.26)\
**Post date:** [June 20, 2019, 11:20am UTC](https://forum.katalon.com/t/if-else-statements-in-katalon/28297/5 "2019-06-20T11:20:12Z")

</div>

Thanks for suggestion again  
Yes I also think VerifyElementPresent is the culprit  
Both of these function should return true or false based on the situation, but I get exceptions, as it is not assert functions why is exception thrown & I have to add unnecessary try catch to handle that.  
VerifyElementVisible is also not solving the purpose  
verifyElementNotPresent when Element is not present it should return true & when it present it should return false, instead of false it throws exception

---

<div class="post-metadata">

**Author:** ![Dominik\_Kreft](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/dominik_kreft/32/5433_2.png) [@Dominik\_Kreft](https://forum.katalon.com/u/Dominik_Kreft)\
**Post date:** [June 20, 2019, 11:36am UTC](https://forum.katalon.com/t/if-else-statements-in-katalon/28297/6 "2019-06-20T11:36:40Z")

</div>

The Issue here is that VerifyElementNotPresent is there to verify that an element is not present… and if it’s present it’s an exception and will stop the program, because that’sn what you want to test with it.  
You just need to add following statement to it:

`WebUI.verifyElementNotPresent(findTestObject(‘Page_SurveyQuestions/span_SurveyPanel’),30, FailureHandling.CONTINUE_ON_FAILURE)`  
OR  
`WebUI.verifyElementNotPresent(findTestObject(‘Page_SurveyQuestions/span_SurveyPanel’),30, FailureHandling.OPTIONAL)`

Continue just continues and gives no error message and Optional will also continue, but will mark this step with a warning.  
If you don’t add anything to it, STOP\_ON\_FAILURE is the standard selection.

Here a link for you for further informations 🙂

> **[Failure Handling](https://docs.katalon.com/katalon-studio/docs/failure-handling.html#in-manual-view)**
>
> Failure handling settings allow users to decide whether Katalon Studio will continue running or not in case of errors occurs during execution. Currently, Katalon Studio supports the following failure handling...

Hope that helps.

---

<div class="post-metadata">

**Author:** ![fluffywaffle](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/fluffywaffle/32/16104_2.png) [@fluffywaffle](https://forum.katalon.com/u/fluffywaffle)\
**Post date:** [February 5, 2020, 2:12am UTC](https://forum.katalon.com/t/if-else-statements-in-katalon/28297/7 "2020-02-05T02:12:40Z")

</div>

thank you for this topic and this has been specifically helpful for me today… both of you, author anjanaiv.26 and solver, Dominik\_Kreft
