Forum Discussion

claudiaborges's avatar
claudiaborges
Occasional Contributor
3 years ago

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

    • claudiaborges's avatar
      claudiaborges
      Occasional Contributor

      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's avatar
        vinniew
        Staff

        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