Using VerifyElementVisible to end while-loop

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}

}

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

But how would i transform that into a boolean?

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)

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.

2 Likes