# If statement does not continue - if false

**URL:** <https://forum.katalon.com/t/if-statement-does-not-continue-if-false/14216>\
**Category:** Miscellaneous\
**Created:** [November 12, 2018, 2:30pm UTC](https://forum.katalon.com/t/if-statement-does-not-continue-if-false/14216 "2018-11-12T14:30:36Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deepa\_Naicker1](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@Deepa\_Naicker1](https://forum.katalon.com/u/Deepa_Naicker1)\
**Post date:** [November 12, 2018, 2:30pm UTC](https://forum.katalon.com/t/if-statement-does-not-continue-if-false/14216/1 "2018-11-12T14:30:36Z")

</div>

Hi there,  
I have an if statement that works when the error is caught and clicks the button to continue:

**if** (WebUI._verifyTextPresent_(‘An error occurred and your order was not placed. Please try again.’, **false** )== **true** )

{

```
WebUI._click_(_findTestObject_('Checkout/PayWithButton'))

```

}

but when there is no error - when the condition is false, it does not continue with the rest of the test case.

I have tried :

**if** (WebUI._verifyTextPresent_(‘An error occurred and your order was not placed. Please try again.’, **false** , FailureHandling. **_CONTINUE\_ON\_FAILURE_** )== **true** )

{

```
WebUI._click_(_findTestObject_('Checkout/PayWithButton'))

```

}

This then has the desired effect, but if the error is caught again - the test fails

How do do i click the button when the error is there and continue and continue if the is no error?

---

<div class="post-metadata">

**Author:** ![Mate\_Mrse](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mate_mrse/32/345_2.png) [@Mate\_Mrse](https://forum.katalon.com/u/Mate_Mrse)\
**Post date:** [November 12, 2018, 2:34pm UTC](https://forum.katalon.com/t/if-statement-does-not-continue-if-false/14216/2 "2018-11-12T14:34:55Z")

</div>

You need to set FailureHandling.OPTIONAL so the test continues execution and if every other step passes, the test status will be “passed”.

Otherwise, if FailureHandling is CONTINUE\_ON\_FAILURE the test will continue but it will be marked as “failed”.

---

<div class="post-metadata">

**Author:** ![Deepa\_Naicker1](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@Deepa\_Naicker1](https://forum.katalon.com/u/Deepa_Naicker1)\
**Post date:** [November 12, 2018, 2:37pm UTC](https://forum.katalon.com/t/if-statement-does-not-continue-if-false/14216/3 "2018-11-12T14:37:32Z")

</div>

When i do use the CONTINUE\_ON\_FAILURE - if the text is “An error occurred and your order was not placed. Please try again” is present the button is not clicked the test then fails - where it should continue

---

<div class="post-metadata">

**Author:** ![Mate\_Mrse](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mate_mrse/32/345_2.png) [@Mate\_Mrse](https://forum.katalon.com/u/Mate_Mrse)\
**Post date:** [November 12, 2018, 2:39pm UTC](https://forum.katalon.com/t/if-statement-does-not-continue-if-false/14216/4 "2018-11-12T14:39:27Z")

</div>

Can you share more of your script?

---

<div class="post-metadata">

**Author:** ![Deepa\_Naicker1](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@Deepa\_Naicker1](https://forum.katalon.com/u/Deepa_Naicker1)\
**Post date:** [November 12, 2018, 2:45pm UTC](https://forum.katalon.com/t/if-statement-does-not-continue-if-false/14216/5 "2018-11-12T14:45:03Z")

</div>

_This is my script and below the error i get in the console:_

_(In this case the error is on the page - but the code is not seeing it - so the test fails)_

**import**  **static** com.kms.katalon.core.checkpoint.CheckpointFactory._findCheckpoint_

**import**  **static** com.kms.katalon.core.testcase.TestCaseFactory._findTestCase_

**import**  **static** com.kms.katalon.core.testdata.TestDataFactory._findTestData_

**import**  **static** com.kms.katalon.core.testobject.ObjectRepository._findTestObject_

**import** com.kms.katalon.core.checkpoint.Checkpoint **as** Checkpoint

**import** com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords **as** CucumberKW

**import** com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords **as** Mobile

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

**import** com.kms.katalon.core.testcase.TestCase **as** TestCase

**import** com.kms.katalon.core.testdata.TestData **as** TestData

**import** com.kms.katalon.core.testobject.TestObject **as** TestObject

**import** com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords **as** WS

**import** com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords **as** WebUI

**import** internal.GlobalVariable **as** GlobalVariable

CustomKeywords._‘customLogin.Login.loginIntoApplicationWith’_()

WebUI._callTestCase_(_findTestCase_(‘AddItemToCart/Cart - AddItem’), [:], FailureHandling. **_STOP\_ON\_FAILURE_** )

WebUI._waitForElementClickable_(_findTestObject_(‘Checkout/ProceedToCheckOutButton’), GlobalVariable._timeout_)

WebUI._click_(_findTestObject_(‘Checkout/ProceedToCheckOutButton’))

WebUI._takeScreenshot_()

WebUI._click_(_findTestObject_(‘Checkout/DeliverMyOrderButton’))

WebUI._click_(_findTestObject_(‘Checkout/SelectDeliveryAddress’))

WebUI._takeScreenshot_()

WebUI._waitForElementPresent_(_findTestObject_(‘Checkout/ContinueButton’), GlobalVariable._timeout_)

WebUI._click_(_findTestObject_(‘Checkout/ContinueButton’))

WebUI._takeScreenshot_()

WebUI._click_(_findTestObject_(‘Checkout/ContinueButton’))

WebUI._waitForElementClickable_(_findTestObject_(‘Checkout/Donat5Button’), GlobalVariable._timeout_)

WebUI._takeScreenshot_()

WebUI._click_(_findTestObject_(‘Checkout/Donat5Button’))

CustomKeywords._‘customPaymentSelector.PaymentSelector.navigatePaymentType’_(‘eBucksSpend your eBucks’)

WebUI._takeScreenshot_()

WebUI._click_(_findTestObject_(‘Checkout/PayWithButton’))

WebUI._waitForPageLoad_(GlobalVariable._timeout_)

//if (WebUI.verifyElementPresent(‘eBucks/ErrorOnCheckoutAlert’, GlobalVariable.timeout) == true)

//{

// WebUI.click(findTestObject(‘Checkout/PayWithButton’))

//}

//if (WebUI.verifyElementPresent(‘eBucks/ErrorOnCheckoutAlert’, GlobalVariable.timeout, FailureHandling.OPTIONAL)== true) {

// WebUI.click(findTestObject(‘Checkout/PayWithButton’))

//}

**if** (WebUI._verifyTextPresent_(‘An error occurred and your order was not placed. Please try again.’, **false** , FailureHandling. **_CONTINUE\_ON\_FAILURE_** )== **true** )

{

```
WebUI._click_(_findTestObject_('Checkout/PayWithButton'))

```

}

WebUI._setText_(_findTestObject_(‘eBucks/RSAIDTextBox’), ‘6805550068084’)

WebUI._setText_(_findTestObject_(‘eBucks/AccountPIN’), ‘2020’)

WebUI._takeScreenshot_()

WebUI._click_(_findTestObject_(‘eBucks/Login’))

WebUI._verifyTextPresent_(‘Pay with eBucks’, **false** )

WebUI._takeScreenshot_()

WebUI._click_(_findTestObject_(‘eBucks/eBucksContinueButton’))

WebUI._takeScreenshot_()

WebUI._click_(_findTestObject_(‘eBucks/PayWithEbucks’))

titel = WebUI._getWindowTitle_()

WebUI._verifyMatch_(titel, ‘Checkout | eBucks’, **false** )

CustomKeywords._‘customLogout.Logout.LogoutAfterConfirmation’_()

ERROR Log

1-12-2018 04:42:01 PM - [START] - Start action : Statement - If (com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyTextPresent(“An error occurred and your order was not placed. Please try again.”, false, CONTINUE\_ON\_FAILURE) == true)

11-12-2018 04:42:01 PM - [INFO] - Checking text present

11-12-2018 04:42:01 PM - [INFO] - Finding text ‘An error occurred and your order was not placed. Please try again.’ on page

11-12-2018 04:42:01 PM - [FAILED] - Text ‘An error occurred and your order was not placed. Please try again.’ is not present on page

11-12-2018 04:42:01 PM - [END] - End action : Statement - If (com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyTextPresent(“An error occurred and your order was not placed. Please try again.”, false, CONTINUE\_ON\_FAILURE) == true)

11-12-2018 04:42:01 PM - [START] - Start action : setText

11-12-2018 04:42:01 PM - [INFO] - Finding Test Object with id ‘Object Repository/eBucks/RSAIDTextBox’

11-12-2018 04:42:01 PM - [INFO] - Checking object

11-12-2018 04:42:01 PM - [INFO] - Checking text

11-12-2018 04:42:01 PM - [INFO] - Checking timeout

11-12-2018 04:42:01 PM - [INFO] - Finding web element with id: ‘Object Repository/eBucks/RSAIDTextBox’ located by ‘By.xpath: //input[@name=‘username’][contains(@id,‘username’)]’ in ‘30’ second(s)

11-12-2018 04:42:32 PM - [INFO] - Unable to find the element located by ‘By.xpath: //input[@name=‘username’][contains(@id,‘username’)]’. Please recheck the objects properties to make sure the desired element is located.

11-12-2018 04:42:32 PM - [INFO] - Begin finding web elements by trial and error method

11-12-2018 04:42:32 PM - [INFO] - Web element found by trial and error method is not used because we can’t guarantee it reflects the intended element. See detailed troubleshooting guide for common issues: [https://docs.katalon.com/x/awXR](https://docs.katalon.com/x/awXR)

11-12-2018 04:42:33 PM - [FAILED] - Unable to set text ‘6809160068084’ of object ‘Object Repository/eBucks/RSAIDTextBox’ (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/eBucks/RSAIDTextBox’ located by ‘By.xpath: //input[@name=‘username’][contains(@id,‘username’)]’ not found)

11-12-2018 04:42:33 PM - [END] - End action : setText

11-12-2018 04:42:33 PM - [FAILED] - Test Cases/eBucksTestCases/eBucks - SuccessfullPayment FAILED because (of) (Stack trace: com.kms.katalon.core.exception.StepFailedException: Text ‘An error occurred and your order was not placed. Please try again.’ is not present on page

at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:32)

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:65)

at com.kms.katalon.core.webui.keyword.builtin.VerifyTextPresentKeyword$\_verifyTextPresent\_closure1.doCall(VerifyTextPresentKeyword.groovy:79)

at com.kms.katalon.core.webui.keyword.builtin.VerifyTextPresentKeyword$\_verifyTextPresent\_closure1.call(VerifyTextPresentKeyword.groovy)

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:21)

at com.kms.katalon.core.webui.keyword.builtin.VerifyTextPresentKeyword.verifyTextPresent(VerifyTextPresentKeyword.groovy:83)

at com.kms.katalon.core.webui.keyword.builtin.VerifyTextPresentKeyword.execute(VerifyTextPresentKeyword.groovy:68)

at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:53)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyTextPresent(WebUiBuiltInKeywords.groovy:1677)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$verifyTextPresent$9.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:141)

at Script1540996771538.run(Script1540996771538.groovy:63)

at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:183)

at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:108)

at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:294)

at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:285)

at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:264)

at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:256)

at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:200)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:99)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:90)

at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149)

at TempTestCase1542033654562.run(TempTestCase1542033654562.groovy:22)

at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)

at groovy.lang.GroovyShell.run(GroovyShell.java:518)

at groovy.lang.GroovyShell.run(GroovyShell.java:507)

at groovy.ui.GroovyMain.processOnce(GroovyMain.java:653)

at groovy.ui.GroovyMain.run(GroovyMain.java:384)

at groovy.ui.GroovyMain.process(GroovyMain.java:370)

at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129)

at groovy.ui.GroovyMain.main(GroovyMain.java:109)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109)

at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131)

)

---

<div class="post-metadata">

**Author:** ![Mate\_Mrse](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/mate_mrse/32/345_2.png) [@Mate\_Mrse](https://forum.katalon.com/u/Mate_Mrse)\
**Post date:** [November 12, 2018, 3:00pm UTC](https://forum.katalon.com/t/if-statement-does-not-continue-if-false/14216/6 "2018-11-12T15:00:40Z")

</div>

The test continued after the “if” branch. This is the reason test failed:

11-12-2018 04:42:33 PM - [FAILED] - Unable to set text ‘6809160068084’ of object ‘Object Repository/eBucks/RSAIDTextBox’ (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/eBucks/RSAIDTextBox’ located by ‘By.xpath: //input[[@name=‘username’][contains(](http://forum.katalon.com/profile//name%3D%27username%27%5D%5Bcontains%28 "Link: http://forum.katalon.com/profile//name%3D%27username%27%5D%5Bcontains%28")[@id](http://forum.katalon.com/profile//id),‘username’)]’ not found)

Are you sure the xpath to the ‘RSAIDTextBox’ is correct?

---

<div class="post-metadata">

**Author:** ![Deepa\_Naicker1](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@Deepa\_Naicker1](https://forum.katalon.com/u/Deepa_Naicker1)\
**Post date:** [November 13, 2018, 5:00am UTC](https://forum.katalon.com/t/if-statement-does-not-continue-if-false/14216/7 "2018-11-13T05:00:19Z")

</div>

Yes because at this stage the error was on the page, but it did not click the button in the if statement, but went straight to the next statement.

---

<div class="post-metadata">

**Author:** ![Deepa\_Naicker1](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@Deepa\_Naicker1](https://forum.katalon.com/u/Deepa_Naicker1)\
**Post date:** [November 13, 2018, 5:39am UTC](https://forum.katalon.com/t/if-statement-does-not-continue-if-false/14216/8 "2018-11-13T05:39:56Z")

</div>

My test is as follows:

> login  
> add item to cart
> 
> > checkout  
> > click pay with button (sometimes in staging when you click this button there is an error on the page - i would just have to click the button again, hence the if statement)  
> > \*when i use the if statement WITHOUT failure handling - if the error is on the page it click the button and continues, however if there is not error on the page it fails to continue with the test  
> > \*when i use the if statement WITH failure handling - if the error is on the page it does not click the button, however if there is no error on the page it continues with the test

Do you think the better approach to be upon error close the browser?

---

<div class="post-metadata">

**Author:** ![B\_L](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/b_l/32/976_2.png) [@B\_L](https://forum.katalon.com/u/B_L)\
**Post date:** [November 13, 2018, 1:49pm UTC](https://forum.katalon.com/t/if-statement-does-not-continue-if-false/14216/9 "2018-11-13T13:49:48Z")

</div>

try

**if** (WebUI._verifyTextPresent_(‘An error occurred and your order was not placed. Please try again.’, **false** , FailureHandling. **_CONTINUE\_ON\_FAILURE_** ))

{

```
WebUI._click_(_findTestObject_('Checkout/PayWithButton'))

```

}

take out the ==true and just verify it passes

another route to try would be:

if (WebUI.verifyElementText(findTestObject(‘your object path here’), ‘An error occurred and your order was not placed. Please try again.’, FailureHandling.CONTINUE\_ON\_FAILURE)) {

WebUI._click_(_findTestObject_(‘Checkout/PayWithButton’))

}

---

<div class="post-metadata">

**Author:** ![ARTI](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@ARTI](https://forum.katalon.com/u/ARTI)\
**Post date:** [November 17, 2018, 10:51am UTC](https://forum.katalon.com/t/if-statement-does-not-continue-if-false/14216/10 "2018-11-17T10:51:11Z")

</div>

> B L said:
> 
> try
> 
> **if** (WebUI._verifyTextPresent_(‘An error occurred and your order was not placed. Please try again.’, **false** , FailureHandling. **_CONTINUE\_ON\_FAILURE_** ))
> 
> {
> 
> ```
> WebUI._click_(_findTestObject_('Checkout/PayWithButton'))
> 
> ```
> 
> }
> 
> take out the ==true and just verify it passes
> 
> another route to try would be:
> 
> if (WebUI.verifyElementText(findTestObject(‘your object path here’), ‘An error occurred and your order was not placed. Please try again.’, FailureHandling.CONTINUE\_ON\_FAILURE)) {
> 
> WebUI._click_(_findTestObject_(‘Checkout/PayWithButton’))
> 
> }

> B L said:
> 
> try
> 
> **if** (WebUI._verifyTextPresent_(‘An error occurred and your order was not placed. Please try again.’, **false** , FailureHandling. **_CONTINUE\_ON\_FAILURE_** ))
> 
> {
> 
> ```
> WebUI._click_(_findTestObject_('Checkout/PayWithButton'))
> 
> ```
> 
> }
> 
> take out the ==true and just verify it passes
> 
> another route to try would be:
> 
> if (WebUI.verifyElementText(findTestObject(‘your object path here’), ‘An error occurred and your order was not placed. Please try again.’, FailureHandling.CONTINUE\_ON\_FAILURE)) {
> 
> WebUI._click_(_findTestObject_(‘Checkout/PayWithButton’))
> 
> }

This is not working …

if (WebUI.VerifyElementChecked(findTestObject(‘Search\_Enable/Page\_nopCommerce administration/input\_Enable Search\_EnableSear’),FailureHandling.CONTINUE\_ON\_FAILURE))

{

```
WebUI.comment('Already enabled')

```

} else {

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

WebUI.comment('Now enabled')

```

}

---

<div class="post-metadata">

**Author:** ![B\_L](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/b_l/32/976_2.png) [@B\_L](https://forum.katalon.com/u/B_L)\
**Post date:** [November 20, 2018, 4:39pm UTC](https://forum.katalon.com/t/if-statement-does-not-continue-if-false/14216/11 "2018-11-20T16:39:03Z")

</div>

> ARTI said:
> 
> This is not working …
> 
> if (WebUI.VerifyElementChecked(findTestObject(‘Search\_Enable/Page\_nopCommerce administration/input\_Enable Search\_EnableSear’),FailureHandling.CONTINUE\_ON\_FAILURE))
> 
> {
> 
> ```
> WebUI.comment('Already enabled')
> 
> ```
> 
> } else {
> 
> ```
> WebUI.click(findTestObject('Search\_Enable/Page\_nopCommerce administration/input\_Enable Search\_EnableSear'))
> 
> WebUI.comment('Now enabled')
> 
> ```
> 
> }

What error are you getting? looking at your script you are missing timeout on the verify element checked. try this:

if (WebUI.VerifyElementChecked(findTestObject(‘Search\_Enable/Page\_nopCommerce administration/input\_Enable Search\_EnableSear’), 3, FailureHandling.CONTINUE\_ON\_FAILURE))

{

```
WebUI.comment('Already enabled')

```

} else {

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

WebUI.comment('Now enabled')

```

}
