Tuesday, August 7, 2012

White - Accessing HTML Documents Inside IE Window or Frame


This is again an existing approach we followed to get the HTML document inside a IE panel window.
We are automating toolbar and it is designed in such a way that HTML document is placed inside a IE panel window. I just wanted to automate this …. I have chosen white to do this.. Though I dont know much about White … i wanted to try this…..
         From one of my friend i heard that using “mshtml” dll  and Native Method Call , i can retrieve the HTML document , i just followed the same approach
Steps Followed :-
- Get the Panel Element Object using White
                SearchCriteria searchCriteria = SearchCriteria.ByControlType(ControlType.Pane);
                Panel pan = mywin.Get<Panel>(searchCriteria);
- Get the System Handle for the identified element object
                IntPtr handle = new IntPtr(pan.AutomationElement.Current.NativeWindowHandle);
- Check the class name/attribute of the panel matches the required class name (Required Class Name can be identified using UI Spy)
       NativeMethods.GetClassName(handle, classname, classname.Capacity);
                if (!classname.Equals(“Internet Explorer_Server”))
                {
                    return null;
                }else {……
 Native Methods.cs will have the list of DLL calls to access the System Native Methods
�
- Register/Inform Windows that i am going to get a HTML object
  int message = NativeMethods.RegisterWindowMessage(“WM_HTML_GETOBJECT”);
- Make sure you are able to communicate to that object and retrieve the object
      intlRes=0;
   HTMLDocument document = null
   NativeMethods.SendMessageTimeout(handle, message, 0, 0, SMTO_ABORTIFHUNG, 1000, out lRes);
            if (!(lRes == 0))
            {
                Guid iid = typeof(mshtml.IHTMLDocument).GUID;
                NativeMethods.ObjectFromLresult(lRes, ref iid, 0, ref document);
            }
  �
  return document;
�
- Once we retrieve the document object , you can call all the JS functions wrapped by document – mshtml object
    For Ex :- You can retrieve the title like document.title
We have written a file NativeMthods.cs which will access the windows native dlls to interact with the Desktop windows.

No comments:

Post a Comment