Forum Discussion

robertmarsh's avatar
robertmarsh
Occasional Contributor
5 years ago
Solved

What's the best way to wait for an object to be closed?

Hi, i've inherited some test cases and although they pass, I am getting the dreaded 'An object recognition hint' warning.   The code in question is waiting for an object to not exist before conti...
  • tristaanogre's avatar
    5 years ago

    I don't like using WaitProperty for the "Exists" property...  if you think about it, the WaitProperty method is being called off the object you're looking to see if it exists.  If that object does not actually exist, how you can call a method?

     

    What I usually do for "wait for not exists" scenario us use WaitChild to find the object (or FindChild or something similar) and then check the exists property of the resulting object and then loop until it no longer exists.

     

    Something like:

     

    // Wait until the template window is not shown anymore. 
    while !RM_App["WaitAliasChild"]("NewTemplate, 500).Exists
        Delay(500)
    

    Caveat: If something goes wrong, this can be an infinite loop. So, I often add a counter to put a limiter on the loop to limit how many times it loops.  But hopefully this should help get you in the right direction.