Forum Discussion

tcuser8's avatar
tcuser8
New Contributor
10 months ago
Solved

Checking until a window doesn't exist

Is there any way to check until a window doesn't exist. An inverse .WaitWindow()? Alternatively, is there a version of .Exists() that just returns bool? I've looked around forums and tried implementi...
  • JDR2500's avatar
    10 months ago

    I would avoid using the Exists method on the window object itself in this case.  The issue is you'll take a performance hit of several seconds when the window no longer exists.  That's because "Exists" waits for the full amount of time specified in your Auto-wait timeout set in the project properties. You could reset the Auto-wait time per Hassan_Ballan's suggestion.

    However, I would suggest using WaitWindow with a loop something like below.  As you can see, I included a counter/timer so that it doesn't get stuck in the loop if the window never closes.

    Set myWindow = xxx.WaitWindow(wndClass, wndCaption, 1, 500)
      x = 0
      While myWindow.Exists and x < 10
        Delay 500
        Set myWindow = xxx.WaitWindow(wndClass, wndCaption, 1, 500)
        x = x +1
      Wend
      
      If Not myWindow.Exists Then
        Log.CheckPoint "Yippie!  The window closed"
        Else
        Log.Message "Sad face.  After waiting five seconds the window is still open"
      End If