Forum Discussion

royd's avatar
royd
Regular Contributor
6 years ago
Solved

Simple do-while question

I am using do-while to wait for an object till becomes visible/available, like so -   let btnSave = page.FindChild("idStr", "submit", 15); do { aqUtils.Delay(100); btnSave.Refresh(...
  • tristaanogre's avatar
    6 years ago

    It doesn't matter...  You can't call "Refresh" on an object that doesn't exist.  So, no matter what you do, that won't work.  Here's what I would suggest.

    let btnSave, count; 
    count = 0'
     do
       {
    count++ btnSave = page.FindChildEx("idStr", "submit", 15, true, 100); } while ((!btnSave.Exists) || (count < 100));

    This will repeat the search for the object each time through the loop.  This is necessary in order to make sure that the object is properly found so that the "Exists" check can happen.  Note that I'm using "FindChildEx" as this has the timeout built in so that we don't need the delay call.

     

    Also, note that I'm adding an additional break out.  The loop will continue infinitely if the object never resolves so I added a max iteration of 100 (10 seconds) to allow for the loop to exit rather than hang your automation.