How to get Window from AutomationElement

Mar 18, 2009 at 9:57 PM
Does anyone know how to get Window from automation element without modifying the source code. It looks like approach suggested before

            var windowsFramework = new WindowsFramework(element.Current.FrameworkId);
            if (windowsFramework.WinForm) return new WinFormWindow(element, option, windowSession);
            else if (windowsFramework.WPF) return new WPFWindow(element, WindowFactory.Desktop, option, windowSession);
            else if (windowsFramework.Win32) return new Win32Window(element, WindowFactory.Desktop, option, windowSession);

is not working anymore because there is no public constructor for window, and types used here are not public either.

Mar 25, 2009 at 1:44 PM
can you explain a bit more about why you cannot use the application of desktop object for getting a window
Apr 22, 2009 at 9:17 PM
I use both White and UIAutomation and at some point have to convert window from one type to another because White doesn't provide all abilities needed. It will be architecturally wrong to pass application name or object all through the code, especially when I work with several applications.
May 8, 2009 at 1:53 PM

Just so that I know more about the issue, can you please explain more about what are the things which are looking from window, but you find them only on AutomationElement.

May 10, 2009 at 5:05 PM

I had similar request on this. My application UI ControlType is Panel but not Window. So I cannot use Desktop.Instance.Window to get it. Instead, I use UIAutomation to get my app's AutomationElement and then use it to create a White's Panel instance.

But Panel class don't provide method to get modal window, so again, I need to create a Window from AutomationElement. Fortunately, I read the following discussion and then add similar method into Panel class. Now it meets my request.


1.  Provide a method in Desktop.Instance to get Panel. I have encountered several apps using Panel, not Window.

2.  Provide a method in Panel to get modal window.


May 20, 2009 at 12:42 PM

For example I have window with title which is changed dinamically and has no automationId. I could get automation element (for example from hwnd or from window class name) but can't get White Window. 

May 25, 2009 at 6:54 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.