# Decision-making 'if' stops the loop

**URL:** <https://forum.katalon.com/t/decision-making-if-stops-the-loop/6636>\
**Category:** Miscellaneous\
**Created:** [October 4, 2017, 8:09am UTC](https://forum.katalon.com/t/decision-making-if-stops-the-loop/6636 "2017-10-04T08:09:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Przemek](https://avatars.discourse-cdn.com/v4/letter/p/96bed5/32.png) [@Przemek](https://forum.katalon.com/u/Przemek)\
**Post date:** [October 4, 2017, 8:09am UTC](https://forum.katalon.com/t/decision-making-if-stops-the-loop/6636/1 "2017-10-04T08:09:43Z")

</div>

Hi there,  
I have problem with the Decision-making statment “IF”. My code looks like this ![](https://s3.amazonaws.com/katalon-forum/editor/py/ypr3gsp95uhu.png)

Why when condition in if is false the whole loop stops?  
I try add "continue statments but it doesn’t work.

[petla\_for.png](https://s3.amazonaws.com/katalon-forum/editor/py/ypr3gsp95uhu.png)

---

<div class="post-metadata">

**Author:** ![Marek\_Melocik](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/marek_melocik/32/371_2.png) [@Marek\_Melocik](https://forum.katalon.com/u/Marek_Melocik)\
**Post date:** [October 4, 2017, 8:20am UTC](https://forum.katalon.com/t/decision-making-if-stops-the-loop/6636/2 "2017-10-04T08:20:38Z")

</div>

You have to add correct FailureHandling behavior to verifyElementPresent keyword. Katalon automatically stops the test when verifyElementPresent is not true (default FailureHandling is Stop on failure).

Try this one (it throws WARNING instead of FAILED) :  
`if (WebUI.verifyElementPresent(newValuePlus, 1, FailureHandling.OPTIONAL))`

---

<div class="post-metadata">

**Author:** ![Przemek](https://avatars.discourse-cdn.com/v4/letter/p/96bed5/32.png) [@Przemek](https://forum.katalon.com/u/Przemek)\
**Post date:** [October 4, 2017, 8:59am UTC](https://forum.katalon.com/t/decision-making-if-stops-the-loop/6636/3 "2017-10-04T08:59:58Z")

</div>

But when I use FailureHandling.OPTIONAL test case result will be Failed?

---

<div class="post-metadata">

**Author:** ![Marek\_Melocik](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/marek_melocik/32/371_2.png) [@Marek\_Melocik](https://forum.katalon.com/u/Marek_Melocik)\
**Post date:** [October 4, 2017, 9:01am UTC](https://forum.katalon.com/t/decision-making-if-stops-the-loop/6636/4 "2017-10-04T09:01:55Z")

</div>

It won’t. It will just log WARNING message that element xxx is not present.

---

<div class="post-metadata">

**Author:** ![Przemek](https://avatars.discourse-cdn.com/v4/letter/p/96bed5/32.png) [@Przemek](https://forum.katalon.com/u/Przemek)\
**Post date:** [October 4, 2017, 10:36am UTC](https://forum.katalon.com/t/decision-making-if-stops-the-loop/6636/5 "2017-10-04T10:36:40Z")

</div>

Okey! thanks 🙂

---

<div class="post-metadata">

**Author:** ![Marek\_Melocik](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/marek_melocik/32/371_2.png) [@Marek\_Melocik](https://forum.katalon.com/u/Marek_Melocik)\
**Post date:** [October 4, 2017, 11:15am UTC](https://forum.katalon.com/t/decision-making-if-stops-the-loop/6636/6 "2017-10-04T11:15:05Z")

</div>

Welcome!

---

<div class="post-metadata">

**Author:** ![Anup\_Nair1](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@Anup\_Nair1](https://forum.katalon.com/u/Anup_Nair1)\
**Post date:** [June 14, 2018, 11:45am UTC](https://forum.katalon.com/t/decision-making-if-stops-the-loop/6636/7 "2018-06-14T11:45:40Z")

</div>

Hello there,

I have a function that checks the presence of an element - DoesElementExists (WebDriver driver,By selector) that i had written in Selenium and i want to use the same in katalon. The problem is if the element does not exist, the If condition fails and the script stops.  
I am not using inbuilt Katalon keyword - VerifyElementPresent as my element property keeps changing each time i visit the page.

For example - I have to check the presence of a date field in a dynamic table and i used to pass the following arguments to the DoesElementPresent function in my selenium script.

if(DoesElementExists(driver, (By.id(“ctl00\_ContentPlaceHolder1\_gvServiceAuditDetail\_ctl0”+i+"\_txtAuditDate"))))

{

driver.findElement(By.id(“ctl00\_ContentPlaceHolder1\_gvServiceAuditDetail\_ctl0”+i+"\_txtAuditDate")).sendKeys(StartDate);

}

This works in Katalon if the element is present. If the element is not present, then the script stops with no element found exception.

Could someone please help me with this? Is there a way i can have a optional failure handling in If condition?
