Method to get a modal dialog box from automation element

Mar 11, 2009 at 6:28 AM

I did a minor change in the White code. It might be useful for you, if you are struggling to search a modal dialog box, or in any situation where you want to create a Window object from an automation element.

Change was done by me in window.cs to get a Window object from an automation element. I added a new method to the Core.UIItems.WindowItems.Window class. The method takes the automation element of the window and initializationoptions and returns a platform specific window object. The basic idea was suggested by Vivek Singh in one of the discussions. Add this code to the proper file and class and then compile your Core project in white code and then use the new Core.dll thus generated in your test projects.




/// <summary>



Creates and returns a platform-specific (win32, winform, WPF) Window object using the AutomationElement pased



/// Created by Ramps1 on 6th Feb 2009



/// </summary>


/// <param name=

"element">window automation element</param>


/// <param name=

"option">initialization options</param>


/// <returns>

Window object created from automationelelment</returns>



public Window GetWindowFromAutomationElement(AutomationElement element,InitializeOption option)




WindowsFramework 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);




return null;



Hope this help someone :)

May 26, 2009 at 6:08 AM

Can you please post the code for the panel and where to add this snippet of code ?

I am also facing the same issue.