This project is read-only.

Detecting when a Window Object is closed

Apr 1, 2008 at 6:56 PM
We want to be able to check that when we have closed a Window that the window has actually been closed. (To close the window we get the Close button from the Window title bar and click it).

We have tried to use the IsClosed property that is available on the Window object but this throws an ElementNotAvailableException when we try and check the property after clicking the Close button.

We also tried checking to see if the Window object is null; but this doesnt work as when the widow is closed the Window object still remains.

I have have looked for some other indication on the Window object to determine if its closed or not and can't find anything to use.

How do you suggest we can check that this Window has been closed?


Apr 1, 2008 at 7:31 PM
OK this seems like a bug which needs to be fixed.
For now you can treat ElementNotAvailableException as indication that the window is closed. This would be fixed in next release.
Apr 2, 2008 at 10:01 AM
Thanks, that would be really helpful.
May 12, 2008 at 5:26 PM
Edited May 12, 2008 at 6:05 PM
I think as a result of fixing this in, you may have broken the work around we previously had i.e.

foreach (Window desktopWindow in White.Desktop.Instance.Windows())
    if (desktopWindow.Name == windowTitle) 
        windowClosed =
           windowClosed =

The stack trace is:
at Core.UIItems.WindowItems.Window.WaitWhileBusy() in d:\white-os\Core\UIItems\WindowItems\Window.cs:line 175
at Core.UIItems.WindowItems.Window..ctor(AutomationElement automationElement, InitializeOption initializeOption, WindowSession windowSession) in d:\white-os\Core\UIItems\WindowItems\Window.cs:line 47
at Core.UIItems.WindowItems.Win32Window..ctor(AutomationElement automationElement, WindowFactory windowFactory, InitializeOption option, WindowSession windowSession) in d:\white-os\Core\UIItems\WindowItems\Win32Window.cs:line 16
at Core.Factory.ChildWindowFactory.Create(AutomationElement element, InitializeOption option, WindowSession windowSession) in d:\white-os\Core\Factory\ChildWindowFactory.cs:line 36
at Core.Factory.WindowFactory.DesktopWindows() in d:\white-os\Core\Factory\WindowFactory.cs:line 147
at Core.Desktop.Windows() in d:\white-os\Core\Desktop.cs:line 58

May 12, 2008 at 5:59 PM
Edited May 12, 2008 at 6:53 PM
Tried using:
window = White.Desktop.Instance.Get<Window>(SearchCriteria.ByText(windowTitle)); 
it fails along the same lines whether or not the window by that title exists. I would expect both cases to be handled properly.
May 13, 2008 at 3:41 AM
I have found the problem. It is happening in my case when I have console window on the desktop.
If you have the same issue then this is the fix.
In Window class and WaitWhileBusy method, you need to change the second line to this.

if (!("ConsoleWindowClass".Equals(automationElement.Current.ClassName) || windowPattern.WaitForInputIdle(CoreAppXmlConfiguration.Instance.BusyTimeout)))

If Console window is not the problem, then do let me know.