# Using VerifyElementVisible to end while-loop

**URL:** <https://forum.katalon.com/t/using-verifyelementvisible-to-end-while-loop/12440>\
**Category:** Miscellaneous\
**Created:** [August 7, 2018, 12:47pm UTC](https://forum.katalon.com/t/using-verifyelementvisible-to-end-while-loop/12440 "2018-08-07T12:47:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marco\_Raphael](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@Marco\_Raphael](https://forum.katalon.com/u/Marco_Raphael)\
**Post date:** [August 7, 2018, 12:47pm UTC](https://forum.katalon.com/t/using-verifyelementvisible-to-end-while-loop/12440/1 "2018-08-07T12:47:35Z")

</div>

Hello,  
i’m trying to use VerifyElementVisible to end a loop but in execution, the script just keeps searching for the element after the 30 seconds standard search time have passed. Here is my script:

Integer RowNr = 1

Boolean Action= false

while (true) {

```
String xpathValue = ('id("postTradeTable")/tbody\[1\]/tr\[' + RowNr) + '\]/td\[4\]/div\[1\]'

TestObject dynamicObject = new TestObject('dynamicObject').addProperty('xpath', com.kms.katalon.core.testobject.ConditionType.EQUALS, 

    xpathValue, true)

RowNr++

WebUI.focus(dynamicObject)

WebUI.click(dynamicObject)

WebUI.rightClick(dynamicObject)

WebUI.delay(1)

```

Action= WebUI.verifyElementVisible(findTestObject(‘Post Trade/Repo/Show Trade/RC/Set repurchase Date’))

if (Action== true){break}

}

---

<div class="post-metadata">

**Author:** ![Andrej\_Podhajsky](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/andrej_podhajsky/32/1055_2.png) [@Andrej\_Podhajsky](https://forum.katalon.com/u/Andrej_Podhajsky)\
**Post date:** [August 7, 2018, 12:56pm UTC](https://forum.katalon.com/t/using-verifyelementvisible-to-end-while-loop/12440/2 "2018-08-07T12:56:17Z")

</div>

try to use WebUI.waitForElementVisible(findTestObject(‘Post Trade/Repo/Show Trade/RC/Set repurchase Date’), 1, FailureHandling.OPTIONAL) instead

---

<div class="post-metadata">

**Author:** ![Marco\_Raphael](https://avatars.discourse-cdn.com/v4/letter/m/f08c70/32.png) [@Marco\_Raphael](https://forum.katalon.com/u/Marco_Raphael)\
**Post date:** [August 7, 2018, 1:10pm UTC](https://forum.katalon.com/t/using-verifyelementvisible-to-end-while-loop/12440/3 "2018-08-07T13:10:39Z")

</div>

But how would i transform that into a boolean?

---

<div class="post-metadata">

**Author:** ![Andrej\_Podhajsky](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/andrej_podhajsky/32/1055_2.png) [@Andrej\_Podhajsky](https://forum.katalon.com/u/Andrej_Podhajsky)\
**Post date:** [August 7, 2018, 1:31pm UTC](https://forum.katalon.com/t/using-verifyelementvisible-to-end-while-loop/12440/4 "2018-08-07T13:31:27Z")

</div>

return value from WebUI.waitForElementVisible() is boolean  
so use it exactly as verifyElementVisible

> - 
> 
> ```
> #### @[CompileStatic](http://groovy.codehaus.org/api/groovy/transform/CompileStatic.html)  
> @com.kms.katalon.core.annotation.Keyword(keywordObject =  
> StringConstants.KW\_CATEGORIZE\_ELEMENT) static boolean  
> **waitForElementVisible** (com.kms.katalon.core.testobject.TestObject  
> to, int timeOut)
> 
>   
> 
> Wait until the given web element is visible within timeout.  
> 
>   
> **throws:**  
> 
> StepFailedException
> 
>   
> 
>   
> **Returns:**  
> 
> true if the element is present and visible; otherwise, false
> 
>   
> 
>   
> **Parameters:**  
> 
> `to` \- represent a web element  
> 
> `timeOut` \- how many seconds to wait (maximum)
> 
> ```

---

<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:** [August 7, 2018, 1:32pm UTC](https://forum.katalon.com/t/using-verifyelementvisible-to-end-while-loop/12440/5 "2018-08-07T13:32:41Z")

</div>

WebUI._waitForElementVisible_ returns boolean. You don’t have to transform anything.

By the way, **while(true)** is really dangerous expression. You should add at least some timeout in case that element won’t appear after x tries.
