WaitForDocumentLoaded not working in IE

Class library usage, coding and language questions.
User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

WaitForDocumentLoaded not working in IE

Post by Aracknid » Thu Jul 31, 2014 8:58 pm

I just updated my systems and I went from Ranorex 4.0.6 to Ranorex 5.1.1. But on the same systems I also did a windows update and went from IE 11.0.9600.17126 to 11.0.9600.17207.

Now suddenly I'm having issues with WaitForDocumentLoaded in some circumstances.

For example, my app starts IE and is presented with a log in page. When I log in, a separate IE window appears (not a tab since I've configured it to launch this way) with my main app. In my code, I'm checking the original windows Web Doc with WaitForDocumentLoaded and it is getting stuck if there is no timeout or catching an error if I gave it a time-out. The error is that it timed-out waiting for the page to load. Using Ranorex Spy, the ready state is Complete.

This also happens when the second window (the main app window) launches another window and I do a WaitForDocumentLoaded on the main apps web doc.

Any ideas?

I tried it in FireFox ESR 24.7 and Chrome 36 and it's fine.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: WaitForDocumentLoaded not working in IE

Post by Support Team » Fri Aug 01, 2014 1:29 pm

Hi Aracknid,

Unfortunately we are not aware of such an issue. It was also not possible for me to reproduce this problem on my machine.

May I ask you to provide a sample solution in order to reproduce this behavior on my side?

If you don’t want to attach the sample here in the public forum you can send it to [email protected]

Regards,
Markus (S)

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: WaitForDocumentLoaded not working in IE

Post by Aracknid » Fri Aug 01, 2014 3:57 pm

The issue seems to be caused by javascript's "window.open" command. If another IE window is opened this way, if you try to WaitForDocumentLoaded on the launching window, it hangs here. Here is some sample code:

NOTE: I didn't want to spend too much time trying to figure out why my sample was not working, so comment out the section that works when you want to test the section that fails and visa versa.

NOTE: To re-iterate, this code WORKED with previous version of IE I was using and Ranorex 4.0.6.
Imports System.Windows.Forms

Module Module1

    'This is an example was written to show an issue with WaitForDocumentLoaded using Ranorex 5.1.1 and IE with version 11.0.9600.17207
    ' The issue appears to be caused by javascript Window.Open command
    'The first example will show launching a second window without using Window.Open, and this works with no issues.
    'The Second example will use a web site that has an example of javascript window.open to launch a second window, and doing the WaitForDocumentLoaded
    'on the first window will fail. Note that this worked with older IE and Ranorex 4.0.6. Not sure where the problem is.... Ranorex or IE

    Sub Main()

        Dim FirstBrowserWebDoc As Ranorex.WebDocument = Nothing
        Dim SecondBrowserWebDoc As Ranorex.WebDocument = Nothing
        Dim ThirdBrowserWebDoc As Ranorex.WebDocument = Nothing
        Dim FourthBrowserWebDoc As Ranorex.WebDocument = Nothing
        Dim ms_AddrURL As String = "www.ranorex.com"
        Dim MyAnchor As Ranorex.ATag = Nothing
        Dim OpenNewWindowMenuItem As Ranorex.MenuItem = Nothing

        Try

            '**********************************
            ' This will work

            System.Diagnostics.Process.Start("iexplore", "about:blank")

            If Not Ranorex.Host.Local.TryFindSingle("/dom[@pageurl='about:blank']", 30000, FirstBrowserWebDoc) Then Stop

            FirstBrowserWebDoc.EnsureVisible()

            FirstBrowserWebDoc.Navigate(ms_AddrURL, False, 120000) ' Wait up to 2 minutes to find/load web page
            If Not Ranorex.Host.Local.TryFindSingle("/dom[@pageurl='http://www.ranorex.com/']", 120000, FirstBrowserWebDoc) Then Stop

            FirstBrowserWebDoc.WaitForDocumentLoaded() 'This will work because it was not spawned from another IE form/window

            'Now open a link in another window

            MyAnchor = FirstBrowserWebDoc.FindSingle(".//li[#'menuitem7']/a[@innertext='FORUM']")

            Ranorex.Mouse.Click(MyAnchor.Element, mousebuttons.right)
            If Not Ranorex.Host.Local.TryFindSingle("/contextmenu[@processname='iexplore']/?/?/menuitem[@accessiblename='Open in new window']", 30000, OpenNewWindowMenuItem) Then Stop
            OpenNewWindowMenuItem.Click()

            Ranorex.Delay.Seconds(2)

            FirstBrowserWebDoc.WaitForDocumentLoaded() 'This will not hang here. IT will work

            If Not Ranorex.Host.Local.TryFindSingle("/dom[@pageurl='http://www.ranorex.com/forum/']", 120000, SecondBrowserWebDoc) Then Stop

            SecondBrowserWebDoc.WaitForDocumentLoaded()
            SecondBrowserWebDoc.Close()
            Ranorex.Delay.Seconds(2)

            'This was causing an error so I commented it out. Not specifically what my issue was, but you can look at it if you want
            'FirstBrowserWebDoc.Close()
            Ranorex.Delay.Seconds(2)
            '
            '***************************

            ' This will fail

            System.Diagnostics.Process.Start("iexplore", "about:blank")

            If Not Ranorex.Host.Local.TryFindSingle("/dom[@pageurl='about:blank']", 30000, ThirdBrowserWebDoc) Then Stop

            ThirdBrowserWebDoc.EnsureVisible()
            Ranorex.Delay.Seconds(2)

            ms_AddrURL = "www.javascript-coder.com/files/window-p ... mple1.html"
            ThirdBrowserWebDoc.Navigate(ms_AddrURL, False, 120000) ' Wait up to 2 minutes to find/load web page

            If Not Ranorex.Host.Local.TryFindSingle("/dom[@pageurl='http://www.javascript-coder.com/files/w ... mple1.html']", 120000, ThirdBrowserWebDoc) Then Stop

            ThirdBrowserWebDoc.WaitForDocumentLoaded() 'This will work because it was not spawned from another IE form/window

            'click the link that does the window.open call
            MyAnchor = ThirdBrowserWebDoc.FindSingle("./body/p[1]/a[@innertext~'^Open\ the\ JavaScript\ Windo']")
            MyAnchor.Click()

            'Now a new window has been launched using javascript window.open. This next line will fail
            'NOTE: Timeout was added to catch the issue
            ThirdBrowserWebDoc.WaitForDocumentLoaded(10000)

            If Not Ranorex.Host.Local.TryFindSingle("/dom[@pageurl='http://www.javascript-coder.com/']", 120000, FourthBrowserWebDoc) Then Stop

            FourthBrowserWebDoc.WaitForDocumentLoaded()
            FourthBrowserWebDoc.Close()
            Ranorex.Delay.Seconds(2)

            SecondBrowserWebDoc.Close()
            Ranorex.Delay.Seconds(2)

        Catch ex As Exception
            Debug.Print(ex.Message)
            Stop
        End Try

    End Sub

End Module

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: WaitForDocumentLoaded not working in IE

Post by Aracknid » Fri Aug 01, 2014 6:51 pm

Fortunately I was able to find a machine that had not been updated with Microsoft Windows Updates, and Installed Ranorex 5.1.1 on it and this problem does occur. So it looks like a Ranorex issue to me, and not a Windows Update issue changing my IE version.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: WaitForDocumentLoaded not working in IE

Post by Support Team » Wed Aug 06, 2014 4:03 pm

Hi Aracknid,

Thank you for providing this code sample.

We will analyze this issue on our machines and I will get back to you as soon as I have any information.

Thank you :)

regards,
Markus (S)

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: WaitForDocumentLoaded not working in IE

Post by Support Team » Fri Aug 22, 2014 1:45 pm

Hi Aracknid,

We were able to reproduce this issue on our machines and we are already working on a fix for this problem.
As a workaround I would suggest to use the TryFindSingle()-Method again before you try to perform an action on the webdocument.

Regards,
Markus (S)