Forum Discussion

hunternemitz's avatar
hunternemitz
New Contributor
11 years ago

Checking for existence of a window without incurring the auto-wait

In my tests, there is one point where I am looking for a dialog pop-up.



If AliasObj.WaitAliasChild("dlgImport").Exists then



The problem is that it incurs the auto wait timeout (which for me is long because load times in my program are sometimes very lengthy).



Is there a way check for the existence of the window, but have it work something like this?...



do while (True)

  if AliasObj.WaitAliasChild('dlgImport").Exists then exit do

  else

    Delay(2000)

  loop



Essentially having it loop until it find the dialog (to allow for dynamic waiting, as the time it takes for the pop up to appear is not consistent).
  • If you're just trying to get around the default timeout, you can just add the waittime to your waitaliaschild call and set it to 0. That way it will check to see if it exists and immediately move on without a delay.





    if AliasObj.WaitAliasChild('dlgImport", 0).Exists then...



    As for generically waiting for something to happen, I wrote a function that I call when I'm waiting on something:






    function waitWhile(condition, msg, timeout)


    '*************************


    '   given a condition, message, and timeout period, 


    '   waits for the condition to be true or the timeout to lapse


    '*************************


        t = 0


        do While eval(condition) and t <= timeout 


            delaytext = t & " of " & timeout & " seconds passed waiting for " & msg


            delay 1000, delaytext


            t = t + 1


        loop


        if t <= timeout then 


            waitWhile = true


        else


            waitWhile = false


        end if


    end function



    So if I was waiting for the window you're waiting on, I'd call it like so:





    if waitWhile("not AliasObj.WaitAliasChild('dlgImport", 0).Exists", "window to load", 30) then

        'it loaded so do something

    else

        'it didn't load, there's a problem

    end if


  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Hi Hunter,



    The AliasObj.WaitAliasChild("dlgImport", XXX) does not need a loop as it will find the alias child as soon as it is available and will wait at most XXX milliseconds.



    As far as I know it is the only Wait function that works that way. All the others would wait until XXX before checking.



    Sincerely