When I use condition in while loop it is failing

I am using the below condition in while loop but the test is failing

while (WebUI.verifyElementVisible(findTestObject(‘ObjectName’)))
{
execute
{

ideally when the object is visible then the while loop should be executed but this fails.

That’s the kind of post that leads to a dozen or more questions.

Post your question again but this time follow this advice:

@Russ_Thomas Sorry for not giving clear information.

I am trying this scenario where I am going to webmail and deleting the email one by one till the emails are deleted .I want to use the while condition till the emails(in this case it is an object) are deleted.

while (WebUI.verifyElementPresent(findTestObject(‘Page_Amazon WorkMail/div_PROD_HIGH Test message’), 30)) {
WebUI.rightClick(findTestObject(‘Page_Amazon WorkMail/div_PROD_HIGH Test message’))

WebUI.click(findTestObject('Page_Amazon WorkMail/span_Delete'))

}

A word of advice…

Go through these actions as a human. Pay particular attention to what you are doing between clicks.

Clue: You are very likely waiting while the webpage updates to show the modified list of emails. Right?

Your test code MUST do the same.

In your pseudo code you used a one-liner - execute. As always, the devil is in the details. That one line is going to have ensure that the webpage is ready before you issue a click.

Second clue: your test code is a robot. A very faithful but very stupid robot. He does exactly what you tell him to do. No more. No less. Teach him how to wait. Teach him how to wait for the same things YOU wait for.

You need to include a FailureHandling argument in verifyElementVisible(), like this:

while (WebUI.verifyElementVisible(findTestObject(‘ObjectName’), FailureHandling.OPTIONAL))

Also, verifyElementVisible() does not take a timeout argument, remove it.

What’s happening when you don’t include this is that when it evaluates to false, a StepFailedException is thrown and the test stops.

1 Like