# If element not found skip to next iteration else continue statement

**URL:** <https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [September 16, 2018, 6:56pm UTC](https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232 "2018-09-16T18:56:15Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinod2](https://avatars.discourse-cdn.com/v4/letter/v/b782af/32.png) [@vinod2](https://forum.katalon.com/u/vinod2)\
**Post date:** [September 16, 2018, 6:56pm UTC](https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232/1 "2018-09-16T18:56:15Z")

</div>

I need help in katalon studio case script for if else statement. If the element ‘Page\_Quick Inbound/input\_Bad\_quantity’ is not found then it should skip the current iteration and continue with the next iteration. 15th line in the code I have tried the if statement but it is not working.

```auto
for (def row = 1; row <= findTestData('Ship Plan Data').getRowNumbers(); row++) {
                 WebUI.delay(2)
                 WebUI.setText(findTestObject('Page_Quick Inbound/input_Scan or type SKU_itemId'), 
                 findTestData('Ship Plan Data').getValue('fnsku', row)) rb.keyPress(KeyEvent.VK_ENTER)
                 WebUI.delay(1)
                 rb.keyRelease(KeyEvent.VK_ENTER)
                 WebUI.delay(2) if (WebUI.verifyElementNotpresent(findTestObject('Page_Quick Inbound/input_Bad_quantity',10,FailureHandling.OPTIONAL) ))
                        {continue} 
        else{
             WebUI.setText(findTestObject('Page_Quick Inbound/input_Bad_quantity'), findTestData('Ship Plan Data').getValue('Quantity',
                                row))
              rb.keyPress(KeyEvent.VK_ENTER)     
              WebUI.delay(2)
              rb.keyRelease(KeyEvent.VK_ENTER)
              WebUI.delay(3) WebUI.setText(findTestObject('Page_Quick Inbound/input_(You can select bin from'), findTestData('Ship Plan Data').getValue(
                                'bin', row)) rb.keyPress(KeyEvent.VK_ENTER)
              WebUI.delay(2)
              rb.keyRelease(KeyEvent.VK_ENTER)
              WebUI.delay(2) WebUI.click(findTestObject('Page_Quick Inbound/button_RECEIVE STORE'))
             }
    } 

```

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [September 16, 2018, 11:04pm UTC](https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232/2 "2018-09-16T23:04:47Z")

</div>

You are using `WebUI.verifyElementNotPresent()`. Calling verifyElementNotPresent makes your script fragile in case that the target web pages responds slowly. If the response is slow (e.g. 3 second), your call to `WebUI.verifyElementNotPresent()` would quickly return true. You should use `WebUI.verifyElementNotPresent()` only when you are 100% sure that the element will be found in the page at the first iteration and you expect it to disappear after a few iteration. I suppose this scenario is not what you have in mind.

Your problem can be restated:

> Wait for the element ‘Page\_Quick Inbound/input\_Bad\_quantity’ to be found; If it is found then the script do something … , otherwise the script skip the current iteration and continue with the next iteration.

You can implement it using `WebUI.verifyElementPresent()`. Your script would be as such:

```auto
....def timeout = 1if (WebUI.verifyElementPresent( findTestObject('Page_Quick Inbound/input_Bad_quantity', timeout, FailureHandling.OPTIONAL) )) { WebUI.setText( findTestObject('Page_Quick Inbound/input_Bad_quantity'), findTestData('Ship Plan Data').getValue('Quantity', row)) ...} else { continue}....

```

Possibly you would prefer shorter timeout, for example 1 sec, to longer timeout, for example 10 secs.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [September 17, 2018, 12:35am UTC](https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232/3 "2018-09-17T00:35:04Z")

</div>

:o

---

<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:** [September 17, 2018, 6:53am UTC](https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232/4 "2018-09-17T06:53:14Z")

</div>

Plus,

```auto
findTestObject('Page_Quick Inbound/input_Bad_quantity',10,FailureHandling.OPTIONAL)accepts only string (test object id/path) as parameter. 

```

---

<div class="post-metadata">

**Author:** ![vinod2](https://avatars.discourse-cdn.com/v4/letter/v/b782af/32.png) [@vinod2](https://forum.katalon.com/u/vinod2)\
**Post date:** [September 17, 2018, 2:40pm UTC](https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232/5 "2018-09-17T14:40:02Z")

</div>

@Mate Mrse and @4280-kazurayam Thanks been trying all possibilities for last 48 hrs. I am not a coder but putting my sincere effort to get this automated. Did try the below as said and got error. Let me know what to be changed.

```auto
for (def row = 1; row <= findTestData('Ship Plan Data').getRowNumbers(); row++) 
{
    WebUI.delay(2)
    WebUI.setText(findTestObject('Page_Quick Inbound/input_Scan or type SKU_itemId'), findTestData('Ship Plan Data').getValue(
    'fnsku', row))
    rb.keyPress(KeyEvent.VK_ENTER)
    WebUI.delay(1)
    rb.keyRelease(KeyEvent.VK_ENTER)
    WebUI.delay(4)
   
def timeout = 3
 if (WebUI.verifyElementPresent(
findTestObject('Page_Quick Inbound/input_Bad_quantity',timeout, FailureHandling.OPTIONAL) )) 
{
      WebUI.setText(findTestObject('Page_Quick Inbound/input_Bad_quantity'), findTestData('Ship Plan Data').getValue('Quantity', 
                row))
        rb.keyPress(KeyEvent.VK_ENTER)
        WebUI.delay(2)
        rb.keyRelease(KeyEvent.VK_ENTER)
        WebUI.delay(3)
        WebUI.setText(findTestObject('Page_Quick Inbound/input_(You can select bin from'), findTestData('Ship Plan Data').getValue(
                'bin', row))
        rb.keyPress(KeyEvent.VK_ENTER)
        WebUI.delay(2)
        rb.keyRelease(KeyEvent.VK_ENTER)
        WebUI.delay(2)
        WebUI.click(findTestObject('Page_Quick Inbound/button_RECEIVE STORE'))
    } else 
{
continue
}
}

```

Test Cases/shipplancase2 FAILED because (of) (Stack trace: groovy.lang.MissingMethodException: No signature of method: Script1536501262795.findTestObject() is applicable for argument types: (java.lang.String, java.lang.Integer, com.kms.katalon.core.model.FailureHandling) values: [Page\_Quick Inbound/input\_Bad\_quantity, 3, OPTIONAL]

---

<div class="post-metadata">

**Author:** ![Gerard\_van\_der\_Winke](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/gerard_van_der_winke/32/22419_2.png) [@Gerard\_van\_der\_Winke](https://forum.katalon.com/u/Gerard_van_der_Winke)\
**Post date:** [September 17, 2018, 3:11pm UTC](https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232/6 "2018-09-17T15:11:27Z")

</div>

timeout (int) is not part of the parms for findTestObject, but for WebUI.verifiyElementPresent.

| Type | Name and description |
| --- | --- |
| `static [TestObject](https://api-docs.katalon.com/studio/v4.6.0.2/api/com/kms/katalon/core/testobject/TestObject.html)` | `**[findTestObject](https://api-docs.katalon.com/studio/v4.6.0.2/api/com/kms/katalon/core/testobject/ObjectRepository.html#findTestObject(java.lang.String))**([String](http://download.oracle.com/javase/6/docs/api/java/lang/String.html "Link: http://download.oracle.com/javase/6/docs/api/java/lang/String.html") testObjectRelativeId)` |
| Finds [TestObject](https://api-docs.katalon.com/studio/v4.6.0.2/api/com/kms/katalon/core/testobject/TestObject.html) by its id or relative id | |
| `static [TestObject](https://api-docs.katalon.com/studio/v4.6.0.2/api/com/kms/katalon/core/testobject/TestObject.html)` | `**[findTestObject](https://api-docs.katalon.com/studio/v4.6.0.2/api/com/kms/katalon/core/testobject/ObjectRepository.html#findTestObject(java.lang.String,%20Map%3CObject,%20Object%3E))**([String](http://download.oracle.com/javase/6/docs/api/java/lang/String.html) testObjectRelativeId, [Map](http://download.oracle.com/javase/6/docs/api/java/util/Map.html)<[Object](http://download.oracle.com/javase/6/docs/api/java/lang/Object.html), [Object](http://download.oracle.com/javase/6/docs/api/java/lang/Object.html)> variables)` |

Finds [TestObject](https://api-docs.katalon.com/studio/v4.6.0.2/api/com/kms/katalon/core/testobject/TestObject.html) by its id or relative id using a variables map to parameterized its properties values  
|

| `static boolean` | `verifyElementPresent(TestObject to, int timeOut, FailureHandling flowControl)`  
Verify if the given web element presents on the DOM |

so

```auto
if (WebUI.verifyElementPresent(
findTestObject('Page_Quick Inbound/input_Bad_quantity',timeout, FailureHandling.OPTIONAL) )) 
{rather should beif (WebUI.verifyElementPresent(
findTestObject('Page_Quick Inbound/input_Bad_quantity') ,timeout, FailureHandling.OPTIONAL) ) 
{

```

---

<div class="post-metadata">

**Author:** ![vinod2](https://avatars.discourse-cdn.com/v4/letter/v/b782af/32.png) [@vinod2](https://forum.katalon.com/u/vinod2)\
**Post date:** [September 18, 2018, 9:38am UTC](https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232/7 "2018-09-18T09:38:46Z")

</div>

Did the above still it never goes to else part. hence tried this to find the element visible/clickable/present

```auto
def clickd = WebUI.verifyElementPresent(findTestObject('Page_Quick Inbound/input_Bad_quantity'))Println(clickd)

```

this does not prints the result

---

<div class="post-metadata">

**Author:** ![Gerard\_van\_der\_Winke](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/gerard_van_der_winke/32/22419_2.png) [@Gerard\_van\_der\_Winke](https://forum.katalon.com/u/Gerard_van_der_Winke)\
**Post date:** [September 18, 2018, 9:53am UTC](https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232/8 "2018-09-18T09:53:56Z")

</div>

Println should be println  
and if that is just your typo error, can you please show some partly console log output

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [September 18, 2018, 12:05pm UTC](https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232/9 "2018-09-18T12:05:07Z")

</div>

vinod,

Could you take a screenshot of the TestObject definition of ‘Page\_Quick Inbound/input\_Bad\_quantity’?

And also we need to see HTML fragment around the element which ‘Page\_Quick Inbound/input\_Bad\_quantity’ is targeted to.

---

<div class="post-metadata">

**Author:** ![vinod2](https://avatars.discourse-cdn.com/v4/letter/v/b782af/32.png) [@vinod2](https://forum.katalon.com/u/vinod2)\
**Post date:** [September 19, 2018, 2:03pm UTC](https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232/10 "2018-09-19T14:03:56Z")

</div>

@4280-kazurayam & @Gerard van der Winkel Thanks I had achieved it using finding text in element ,

```auto
WebUI.navigateToUrl('https://www.amazon.in/')
WebUI.setText(findTestObject('Object Repository/Page_Amazon Sign In/input_Email or mobile phone nu'), 'ABC@XYZ.COM')
WebUI.setEncryptedText(findTestObject('Object Repository/Page_Amazon Sign In/input_Forgot Password_password'), 
    'ABC')
WebUI.click(findTestObject('Object Repository/Page_Amazon Sign In/input_Enter your password_reme'))
WebUI.click(findTestObject('Object Repository/Page_Amazon Sign In/input_Enter your password_sign'))
WebUI.click(findTestObject('Object Repository/Page_Two-Step Verification/span_Text me at my number endi'))
WebUI.click(findTestObject('Object Repository/Page_Two-Step Verification/input_Call me at my number end'))
WebUI.delay(15)
WebUI.click(findTestObject('Object Repository/Page_Orders/i_Orders_was-inventory-icon'))
WebUI.click(findTestObject('Object Repository/Page_Orders/i_Load More_was-receive-and-st'))
WebUI.setText(findTestObject('Page_Quick Inbound/input_Scan or Search Shipment'), '121W22HM')
Robot rb = new Robot()
rb.keyPress(KeyEvent.VK_ENTER)
WebUI.delay(1)
rb.keyRelease(KeyEvent.VK_ENTER)
WebUI.delay(5)
for (def row = 1; row <= findTestData('Ship Plan Data').getRowNumbers(); row++) {
    WebUI.waitForElementPresent(findTestObject('Page_Quick Inbound/input_Scan or type SKU_itemId'), 10)
WebUI.delay(4)
WebUI.setText(findTestObject('Page_Quick Inbound/input_Scan or type SKU_itemId'), findTestData('Ship Plan Data').getValue('fnsku', row))
    rb.keyPress(KeyEvent.VK_ENTER)
    WebUI.delay(1)
    rb.keyRelease(KeyEvent.VK_ENTER)
    WebUI.delay(4)
    if (WebUI.verifyElementText(findTestObject('Object Repository/Page_Quick Inbound/div_Please update the dimensio'), 'Please update the dimensions of the product and try again', 
        FailureHandling.CONTINUE_ON_FAILURE) == true) {
        continue
    } else {
        WebUI.waitForElementPresent(findTestObject('Page_Quick Inbound/input_Bad_quantity'), 20)
        WebUI.delay(4)
        WebUI.setText(findTestObject('Page_Quick Inbound/input_Bad_quantity'), findTestData('Ship Plan Data').getValue('Quantity', 
                row))
        WebUI.delay(1)
        rb.keyPress(KeyEvent.VK_ENTER)
        WebUI.delay(2)
        rb.keyRelease(KeyEvent.VK_ENTER)
        WebUI.delay(5)
        WebUI.setText(findTestObject('Page_Quick Inbound/input_(You can select bin from'), findTestData('Ship Plan Data').getValue(
                'bin', row))
        rb.keyPress(KeyEvent.VK_ENTER)
        WebUI.delay(2)
        rb.keyRelease(KeyEvent.VK_ENTER)
        WebUI.delay(2)
        WebUI.click(findTestObject('Page_Quick Inbound/button_RECEIVE STORE'))
    }
}

```

Now I need to exit for loop if the page title is matched for that I have tried the below code

```auto
title = WebUI.getWindowTitle()
WebUI.verifyMatch(title, 'Amazon Sign In', true)

```

plan to put this below the for statement and don’t know how to exit the for loop but it should continue from the iteration where it left. This is because this website throws me out and brings sign in page. Hence need to sign in again and continue iteration

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [September 19, 2018, 2:11pm UTC](https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232/11 "2018-09-19T14:11:35Z")

</div>

WebUI.verifyMatch() returns Boolean result

- [https://docs.katalon.com/display/KD/[Common]+Verify+Match](https://docs.katalon.com/display/KD/%5BCommon%5D+Verify+Match)

Therefore you can do something like this:

```auto
for (loop) {
    ....
    title = WebUI.getWindowTitle()
    def result = WebUI.verifyMatch(title, 'Amazon Sign In', true)
    if (result) {
       // break or continue
    } else {
       // break or continue
    } ....
}

```

---

<div class="post-metadata">

**Author:** ![vinod2](https://avatars.discourse-cdn.com/v4/letter/v/b782af/32.png) [@vinod2](https://forum.katalon.com/u/vinod2)\
**Post date:** [September 19, 2018, 2:26pm UTC](https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232/12 "2018-09-19T14:26:38Z")

</div>

```auto
 Sign In
 ....
 for ( loop) {
     title = WebUI.getWindowTitle()
     def result = WebUI.verifyMatch(title, 'Amazon Sign In', true)
 if (result) {
              // It should go to sigin in step and 
                 move to else part and it should continue the iteration where it left
 } else {
      ..... 
   }
   ....
}

```

```auto

```

---

<div class="post-metadata">

**Author:** ![vinod2](https://avatars.discourse-cdn.com/v4/letter/v/b782af/32.png) [@vinod2](https://forum.katalon.com/u/vinod2)\
**Post date:** [September 19, 2018, 2:34pm UTC](https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232/13 "2018-09-19T14:34:22Z")

</div>

@4280-kazurayam so if the sign in page is found it should sign in and proceed with iteration code which is present in else part, can duplicate the signin part in title match condition but how to proceed in with sequence continuation

---

<div class="post-metadata">

**Author:** ![vinod2](https://avatars.discourse-cdn.com/v4/letter/v/b782af/32.png) [@vinod2](https://forum.katalon.com/u/vinod2)\
**Post date:** [September 19, 2018, 3:00pm UTC](https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232/14 "2018-09-19T15:00:34Z")

</div>

> kazurayam said:
> 
> vinod,
> 
> Could you take a screenshot of the TestObject definition of ‘Page\_Quick Inbound/input\_Bad\_quantity’?
> 
> And also we need to see HTML fragment around the element which ‘Page\_Quick Inbound/input\_Bad\_quantity’ is targeted to.

![](https://s3.amazonaws.com/katalon-forum/editor/p8/6mswxax0ceje.jpg "Image: https://s3.amazonaws.com/katalon-forum/editor/p8/6mswxax0ceje.jpg")

@4280-kazurayam hope this is the one which you had asked. the “0” box is the Page\_Quick Inbound/input\_Bad\_quantity I guess all these are hidden and enabled at we proceed. It that the reason I was not successful with VerifyElementPresent. sharing you another screen shot where the qty box is not present. ![](https://s3.amazonaws.com/katalon-forum/editor/ox/fpatugbf0bm4.jpg)

[azpage.jpg](https://s3.amazonaws.com/katalon-forum/editor/p8/6mswxax0ceje.jpg)

[azpage2.jpg](https://s3.amazonaws.com/katalon-forum/editor/ox/fpatugbf0bm4.jpg)

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [September 20, 2018, 12:58am UTC](https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232/15 "2018-09-20T00:58:32Z")

</div>

vinod,

Thank you for providing screenshots. But I am afraid I am lost.

Your previsous comment makes me confused:

> Now I need to exit for loop if the page title is matched for that I have tried the below code
> 
> ```auto
> title = WebUI.getWindowTitle()
> 
> ```

WebUI.verifyMatch(title, ‘Amazon Sign In’, true)

> ```auto
> 
>   
> plan to put this **below the for statement**
> 
> ```

What do I mean?

I would see the following code sequence reasonable:

```auto
WebUI.navigateToUrl('https://www.amazon.in/')def title = WebUI.getWindowTitle()if (WebUI.verifyMatch(title, 'Amazon Sign In'), true) { // login processing if necessary}...for (def row = 1; row <= findTestData('Ship Plan Data').getRowNumbers(); row++) { // do something for each entry of the Ship Plan Data}

```

But the following code sequence seems to be a riddle for me:

```auto
WebUI.navigateToUrl('https://www.amazon.in/')...for (def row = 1; row <= findTestData('Ship Plan Data').getRowNumbers(); row++) { def title = WebUI.getWindowTitle() if (WebUI.verifyMatch(title, 'Amazon Sign In'), true) { // login processing } // do something for each entry of the Ship Plan Data}

```

You said you “plan to put this below the for statement”, which would mean you want the latter code sequence… I am lost.

---

<div class="post-metadata">

**Author:** ![vinod2](https://avatars.discourse-cdn.com/v4/letter/v/b782af/32.png) [@vinod2](https://forum.katalon.com/u/vinod2)\
**Post date:** [September 20, 2018, 1:10am UTC](https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232/16 "2018-09-20T01:10:59Z")

</div>

After sign for the first time then ship plan iteration begins.The website throws a sign in page in suddenly hence wanted to sign-in again and then continue with iteration let’s say after 100 th ( indicativei) iteration it shows a sign in page,we need to sigin and then proceed with 101 record of iteration

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [September 20, 2018, 1:17am UTC](https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232/17 "2018-09-20T01:17:40Z")

</div>

Then the latter script is what you want, isn’t it?

```auto
WebUI.navigateToUrl('https://www.amazon.in/')...for (def row = 1; row <= findTestData('Ship Plan Data').getRowNumbers(); row++) { def title = WebUI.getWindowTitle() if (WebUI.verifyMatch(title, 'Amazon Sign In'), true) { // login processing if necessary } // do something for each entry of the Ship Plan Data}

```

---

<div class="post-metadata">

**Author:** ![Jass](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/jass/32/9588_2.png) [@Jass](https://forum.katalon.com/u/Jass)\
**Post date:** [October 9, 2019, 7:41am UTC](https://forum.katalon.com/t/if-element-not-found-skip-to-next-iteration-else-continue-statement/13232/18 "2019-10-09T07:41:55Z")

</div>

To whom it may concern,

In Katalon Studio 7.0.0, we have already fixed the bug that caused the `verifyElementPresent()` and `verifyElementNotPresent()` keywords to throw an exception instead of returning `false` when the verified elements do not exist.

Please first check out the [release note](https://docs.katalon.com/katalon-studio/new/version-70.html#version-70-beta) and click [here](https://github.com/katalon-studio/katalon-studio/releases) to download if you want to try version 7.0.0 (beta) in advance.

Happy Testing!

Jass
