cancel
Showing results for 
Search instead for 
Did you mean: 

How to stop the while loop

claudiaborges
Occasional Contributor

How to stop the while loop

I need to close all the objects on a page (minus one) if they are present. 

I am trying several ways to make a while loop on both keyword tests as in javascript, but they don't do what I want. 

They do close all items but they run one more time to check if the item is present and it is not so they give an error. (and this is not an error, it should indeed stop)

 

the javascript was something like this (this one is not working)

function WhileWidgetExists()
{
var i = 1;
while (i > 3) {
iconDeleteWidget.Click();
i++;
if (i = 1) {
break;
}
}
}

 

4 REPLIES 4
vinniew
Staff

Re: How to stop the while loop

Hi @claudiaborges  

 

Thanks for reaching out. 

 

The loop should stop when the condition returns false. 

 

That being said you can use go to labels to change the execution flow

 

For more info 

 

See 

 

https://support.smartbear.com/testcomplete/docs/keyword-testing/reference/statements/go-to-label.htm...

 

Let me know how this works 

 

KR 

 

Vincent 

claudiaborges
Occasional Contributor

Re: How to stop the while loop

The loop works, but my problem is that the result of the condition returning false before it stops, is that the item is marked as red on the results, as in my screenshot

About the flag, if i add it, it does not loop until there is no more to delete , it deletes only one item. 

 

vinniew
Staff

Re: How to stop the while loop

Hi @claudiaborges 

 

Thanks for pointing that out. 

 

The error suggests that the object was not found during the operation. 

 

Which object is it? 

 

I wonder is it timing out as a result of the loop and the object not being found. 

 

This could one of a number of reasons,

 

What is the details of the error telling us? 

 

While I wait for that, it might help if we add a delay to that operation just as a short term way of checking does it still give us the same error while looping. 

 

From there we can look at addressing this better if the delay works. 

 

KR 

 

Vincent

claudiaborges
Occasional Contributor

Re: How to stop the while loop

Hi, Thanks for reacting

The item is not been found because the while deletes it as it is supposed to do. ( while 'x' present, delete it). 

The last step from the while, it sees there is no more item to delete and it stops, as it is supposed to do. 

The only problem is that in the result it shows as 'red'  as not found but i would like to have it ' green'  as it is supposed to dont find the item. 

 

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors