This project is read-only.

ElementNotAvailableException while using application.GetWindows()

Nov 17, 2010 at 1:26 PM

While retreiving windows using application.GetWindows() method:

var windowstemp = (from window in MainApplication.GetWindows() where window.Title == "Export to..." select window).ToList();

sometimes i receive next exception: ElementNotAvailableException (the target element corresponds to UI that is no longer available (for example, the parent window has closed). 

Any ideas how to resolve this problem&


Nov 23, 2010 at 1:52 PM

This is a known issue, it would be fixed in next release.

Apr 26, 2012 at 12:18 PM

I am getting the same exception above in my tests. The tests sometimes pass and other times fails with that exception, making my tests a bit fragile. Has there been any solution or work around to this problem yet?

Apr 26, 2012 at 12:33 PM

Hi I have written a little operation to get rid of this problem:


 /// <summary>
    /// Gets the windows.
    /// </summary>
    /// <param name="count">The count.</param>
    /// <returns></returns>
    public static List<Window> GetWindows(int count = 0)
      List<Window> windows;
        windows = MyApplication.GetWindows();
      catch (ElementNotAvailableException)
        if (count < 5)
          windows = GetWindows(count + 1);

      return windows;

Hope that helps



Apr 29, 2012 at 6:07 PM

That was a great help. It works now like magic. Thanks a lot.