Using White with a Webpage Containing Frames

Sep 11, 2009 at 3:04 PM

I’m trying to automate a web application (ASP) that contains a lot of Frames on it.  But both from White and UISpy I cannot see any of the frames.  Below is the LogStructure.  Any ideas?

I have an existing application that uses mostly ASP,  that we are introducing some Silverlight stuff into.  I have the Silverlight part working, I just can’t see anything else.

Any help is appreciated.

Thanks, 

Geremy

 

Log Structure:

[2009-09-11 08:59:44,602][INFO ] Using BusyTimeout=5000 for White/Core

[2009-09-11 08:59:44,633][INFO ] Using WaitBasedOnHourGlass=True for White/Core

[2009-09-11 08:59:44,633][INFO ] Using LogActions=False for White/Core

[2009-09-11 08:59:44,633][INFO ] Using WorkSessionLocation=. for White/Core

[2009-09-11 08:59:44,633][INFO ] Using UIAutomationZeroWindowBugTimeout=5000 for White/Core

[2009-09-11 08:59:44,633][INFO ] Using PopupTimeout=5000 for White/Core

[2009-09-11 08:59:44,633][INFO ] Using TooltipWaitTime=0 for White/Core

[2009-09-11 08:59:44,633][INFO ] Using SuggestionListTimeout=3000 for White/Core

[2009-09-11 08:59:44,633][INFO ] Using DefaultDateFormat=Month,Day,Year for White/Core

[2009-09-11 08:59:44,633][INFO ] Using DragStepCount=1 for White/Core

[2009-09-11 08:59:44,633][INFO ] Using InProc=False for White/Core

[2009-09-11 08:59:44,805][INFO ] AutomationId:

ControlType: ControlType.Window

Name: MyWindowName - Windows Internet Explorer

HelpText:

Bounding rectangle: 0,0,1280,964

ClassName: IEFrame

IsOffScreen: False

FrameworkId: Win32

ProcessId: 2416

 

System.Windows.Automation.WindowPattern

System.Windows.Automation.TransformPattern

 

    AutomationId:

    ControlType: ControlType.Pane

    Name: MyWindowName - Windows Internet Explorer

    HelpText:

    Bounding rectangle: 4,30,1272,930

    ClassName: TabWindowClass

    IsOffScreen: False

    FrameworkId: Win32

    ProcessId: 2416

 

 

        AutomationId:

        ControlType: ControlType.Pane

        Name:

        HelpText:

        Bounding rectangle: 4,30,1272,930

        ClassName: Shell DocObject View

        IsOffScreen: False

        FrameworkId: Win32

        ProcessId: 2416

 

 

            AutomationId:

            ControlType: ControlType.Pane

            Name: PaneNameHere

            HelpText:

            Bounding rectangle: 4,30,1272,930

            ClassName: Internet Explorer_Server

            IsOffScreen: False

            FrameworkId: Win32

            ProcessId: 2416

 

            System.Windows.Automation.ValuePattern

 

    AutomationId:

    ControlType: ControlType.Pane

    Name: ITBarHost

    HelpText:

    Bounding rectangle: 4,30,1272,6

    ClassName: InternetToolbarHost

    IsOffScreen: False

    FrameworkId: Win32

    ProcessId: 2416

 

 

    AutomationId: TitleBar

    ControlType: ControlType.TitleBar

    Name: MyWindowName - Windows Internet Explorer

    HelpText:

    Bounding rectangle: 4,4,1272,26

    ClassName:

    IsOffScreen: False

    FrameworkId: Win32

    ProcessId: 2416

 

 

        AutomationId: SystemMenuBar

        ControlType: ControlType.MenuBar

        Name: System Menu Bar

        HelpText:

        Bounding rectangle: 4,4,18,25

        ClassName:

        IsOffScreen: False

        FrameworkId: Win32

        ProcessId: 2416

 

 

            AutomationId: Item 1

            ControlType: ControlType.MenuItem

            Name: System

            HelpText:

            Bounding rectangle: 4,4,18,25

            ClassName:

            IsOffScreen: False

            FrameworkId: Win32

            ProcessId: 2416

 

            System.Windows.Automation.ExpandCollapsePattern

 

        AutomationId: Minimize

        ControlType: ControlType.Button

        Name: Minimize

        HelpText:

        Bounding rectangle: 1204,4,24,24

        ClassName:

        IsOffScreen: False

        FrameworkId: Win32

        ProcessId: 2416

 

        System.Windows.Automation.InvokePattern

 

        AutomationId: Maximize

        ControlType: ControlType.Button

        Name: Maximize

        HelpText:

        Bounding rectangle: 1228,4,24,24

        ClassName:

        IsOffScreen: False

        FrameworkId: Win32

        ProcessId: 2416

 

        System.Windows.Automation.InvokePattern

 

        AutomationId: Close

        ControlType: ControlType.Button

        Name: Close

        HelpText:

        Bounding rectangle: 1252,4,24,24

        ClassName:

        IsOffScreen: False

        FrameworkId: Win32

        ProcessId: 2416

 

        System.Windows.Automation.InvokePattern

 

 

Sep 16, 2009 at 1:07 PM
Edited Sep 16, 2009 at 1:09 PM

Hi Geremy,

The problem is that IE checks for crossframes wich is a security issue. Please take a look at my code maybe it's a help. It's not with White but I think you can figure that out. Maybe it is not implemented in White yet and it should ...

Succes!

Roel Alblas

using System;
using System.Threading;
using System.Runtime.InteropServices;
using Code;
using SHDocVw;
using MSHTML;
using System.Windows.Forms;

namespace Lion
{
    public partial class SearchInLion : Form
    {
        public SearchInLion()
        {
            InitializeComponent();
        }

        AutoResetEvent documentComplete;
        
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (tbPostcode.Text == "")
            {
                MessageBox.Show("Gelieve een zoekcriteria in te vullen");
                return;
            }

            InternetExplorerClass ie = new InternetExplorerClass();

            documentComplete = new AutoResetEvent(false);
            ie.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(OnIEDocumentComplete);
            
            ie.Visible = true;

            object missing = new object();

            ie.Navigate("http://**********************************************", ref missing, ref missing, ref missing, ref missing);            

            documentComplete.WaitOne();

            HTMLDocument doc = ie.Document as HTMLDocument;
            doc.getElementById("txtUserName").setAttribute("value", "*********", 0);
            doc.getElementById("txtPassword").setAttribute("value", "*********", 0);
            doc.getElementById("btnOK").click();

            documentComplete.WaitOne();

            ie.Navigate("http://**********************************************", ref missing, ref missing, ref missing, ref missing);

            while (ie.ReadyState != tagREADYSTATE.READYSTATE_COMPLETE)
            {
                System.Threading.Thread.Sleep(250);
            }

            IHTMLDocument2 m_htmlDoc2 = ie.Document as IHTMLDocument2;
            IHTMLFramesCollection2 frameCol = m_htmlDoc2.frames as IHTMLFramesCollection2;
            IHTMLElementCollection ElementCollection;

            for (int i = 0; i < frameCol.length; i++)
            {
                object i2 = i;

                if (frameCol.item(ref i2) is IHTMLWindow2 && i == 1)
                {
                    IHTMLWindow2 w2 = frameCol.item(ref i2) as IHTMLWindow2;
                    IHTMLDocument2 FrameDoc = CrossFrameIE.GetDocumentFromWindow(w2);
                    ElementCollection = FrameDoc.all;

                    foreach (IHTMLElement htmlele in ElementCollection)
                    {
                        if (htmlele.tagName == "IFRAME")
                        {
                            HTMLIFrame frm = (HTMLIFrame)htmlele;
                            DispHTMLDocument docfrm = (DispHTMLDocument)((IWebBrowser2)frm).Document;

                            IHTMLElementCollection elecoll = docfrm.all as IHTMLElementCollection;

                            foreach (IHTMLElement htmlele2 in elecoll)
                            {
                                if (htmlele2.tagName == "INPUT" && htmlele2.id == "VT_KLANT_PC")
                                {
                                    htmlele2.innerText = tbPostcode.Text;
                                }

                                if (htmlele2.tagName == "INPUT" && htmlele2.id == "btnSearch")
                                {
                                    htmlele2.click();
                                }
                            }
                        }                        
                    }
                }
            }
       }

        private void OnIEDocumentComplete(object pDisp, ref object URL)
        {
            documentComplete.Set();
        }
    }
}
// FREE code from CODECENTRIX
// http://www.codecentrix.com/
// http://codecentrix.blogspot.com/
using System;
using System.Runtime.InteropServices;
using MSHTML;


namespace Code
{
    public class CrossFrameIE
    {
        // Returns null in case of failure.
        public static IHTMLDocument2 GetDocumentFromWindow(IHTMLWindow2 htmlWindow)
        {
            if (htmlWindow == null)
            {
                return null;
            }

            // First try the usual way to get the document.
            try
            {
                IHTMLDocument2 doc = htmlWindow.document;
                return doc;
            }
            catch (COMException comEx)
            {
                // I think COMException won't be ever fired but just to be sure ...
                if (comEx.ErrorCode != E_ACCESSDENIED)
                {
                    return null;
                }
            }
            catch (System.UnauthorizedAccessException)
            {
            }
            catch
            {
                // Any other error.
                return null;
            }

            // At this point the error was E_ACCESSDENIED because the frame contains a document from another domain.
            // IE tries to prevent a cross frame scripting security issue.
            try
            {
                // Convert IHTMLWindow2 to IWebBrowser2 using IServiceProvider.
                IServiceProvider sp = (IServiceProvider)htmlWindow;

                // Use IServiceProvider.QueryService to get IWebBrowser2 object.
                Object brws = null;
                sp.QueryService(ref IID_IWebBrowserApp, ref IID_IWebBrowser2, out brws);

                // Get the document from IWebBrowser2.
                SHDocVw.IWebBrowser2 browser = (SHDocVw.IWebBrowser2)(brws);

                return (IHTMLDocument2)browser.Document;
            }
            catch
            {
            }

            return null;
        }

        private const int E_ACCESSDENIED = unchecked((int)0x80070005L);
        private static Guid IID_IWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046");
        private static Guid IID_IWebBrowser2 = new Guid("D30C1661-CDAF-11D0-8A3E-00C04FC9E26E");
    }

    // This is the COM IServiceProvider interface, not System.IServiceProvider .Net interface!
    [ComImport(), ComVisible(true), Guid("6D5140C1-7436-11CE-8034-00AA006009FA"),
    InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IServiceProvider
    {
        [return: MarshalAs(UnmanagedType.I4)]
        [PreserveSig]
        int QueryService(ref Guid guidService, ref Guid riid, [MarshalAs(UnmanagedType.Interface)] out object ppvObject);
    }
}