0

Detect when a web page is loaded without using sleep

The code below, which came from code in the "UPD2:" section of the above link, does not work. The objIE.getProperty is returning nothing, so it never matches the first tokenized instance strSignature. I was able to isolate that the For Each statement is not locating the open browser instance. Can you please help me fix the code?

I'm on Windows 7 with IE9. My company will soon be upgrading to IE11. I don't think that makes any difference, as I was able to validate that the initial tokenized strSignature is working and being retained. It's just not locating the open browser window and therefore unable to grab the second token for comparison.

For Each objIE In CreateObject("Shell.Application").Windows
  ' loop through all explorer windows to find tokenized instance
  If objIE.GetProperty("marker") = strSignature

As requested here is the full code/paste from the reference link above to make the question more self-contained.

'UPD2: You wrote that IE gets disconnected as the login pop-up comes in, hypothetically there is a way to catch disconnection, and then get IE instance again. Note this is "abnormal programming" :) I hope this helps:
Option Explicit
Dim objIE, strSignature, strInitType

Set objIE = CreateObject("InternetExplorer.Application") ' create IE instance
objIE.Visible = True
strSignature = Left(CreateObject("Scriptlet.TypeLib").GUID, 38) ' generate uid
objIE.putproperty "marker", strSignature ' tokenize the instance
strInitType = TypeName(objIE) ' get typename
objIE.Navigate "https://www.yahoo.com/"
MsgBox "Initial type = " & TypeName(objIE) ' for visualisation

On Error Resume Next
Do While TypeName(objIE) = strInitType ' wait until typename changes (ActveX disconnection), may cause error 800A000E if not within OERN
    WScript.Sleep 10
Loop
MsgBox "Changed type = " & TypeName(objIE) ' for visualisation

Set objIE = Nothing ' excessive statement, just for clearance
Do
    For Each objIE In CreateObject("Shell.Application").Windows ' loop through all explorer windows to find tokenized instance
        If objIE.getproperty("marker") = strSignature Then ' our instance found
            If TypeName(objIE) = strInitType Then Exit Do ' may be excessive type check
        End If
    Next
    WScript.Sleep 10
Loop
MsgBox "Found type = " & TypeName(objIE) ' for visualisation
On Error GoTo 0

Do While objIE.ReadyState <> 4 ' conventional wait if instance not ready
    WScript.Sleep 10
Loop

MsgBox "Title = " & objIE.Document.Title ' for visualisation
Community
  • 1
  • 1
mistrog
  • 1
  • 1
  • Could you add code from the reference to make the question more self-contained? Thanks. – C R Dec 18 '14 at 20:18
  • full code added. thank for the help. – mistrog Dec 18 '14 at 20:38
  • Note: linked answer was deleted by user. – Ansgar Wiechers Dec 18 '14 at 21:18
  • What linked answer was deleted by what user? I went to the original post/link I provided above and it's still there. Please help me understand – mistrog Dec 18 '14 at 21:55
  • The link goes to an answer that was deleted by the user who posted it a couple hours ago (only visible to users with 10k+ reputation). The question to which the answer was posted still exists, though, so the link is redirected there. I guess you actually meant to link to [this answer](http://stackoverflow.com/a/23232573/1630171). – Ansgar Wiechers Dec 18 '14 at 22:50
  • Struggling to understand what you are tring to point out to me. I think you are telling me that the solution on the source post was recnetly corrected. I compared my link above to your answer link. The UPD2 code section is identical. Only the code under the "You can get all text nodes, links etc. from DOM, as follows:" section has changed. The problem is I'm not concerned with that section. I don't know what DOMs are, but that does not appear to fix the section above. It's appears that it is completely different and was not mean to correct the code in the UPD2 section. – mistrog Dec 19 '14 at 16:38
  • I don't know what text nodes are either. – mistrog Dec 19 '14 at 17:36
  • Additional info: I don't want code that can find an open browser with a certain url or title, because the user may already have another instance of the same site open on their pc, and it may through off my automation which they will be using, unless I force close all all their open browser instances first...and I don't want to do that to the user either. What I need is a way to to make sure a specific page is fully loaded when IE object gets disconnected as the AD authencation happens. This is why I like the tokenized method. – mistrog Dec 19 '14 at 17:41

0 Answers0