Try this one, it helped me to solve similar problem with IE once:
Set oIE = CreateObject("InternetExplorer.application")
oIE.Visible = True
oIE.navigate ("http://technopedia.com")
Do While oIE.ReadyState = 4: WScript.Sleep 100: Loop
Do While oIE.ReadyState <> 4: WScript.Sleep 100: Loop
' example ref to DOM
MsgBox oIE.Document.GetElementsByTagName("div").Length
UPD: Drilling down IE events I found that IE_DocumentComplete
is the last event before the page is actually ready. So there is one more method to detect when a web page is loaded (note that you have to specify the exact destination URL which may differ from the target URL eg in case of redirection):
option explicit
dim ie, targurl, desturl, completed
set ie = wscript.createobject("internetexplorer.application", "ie_")
ie.visible = true
targurl = "http://technopedia.com/"
desturl = "http://technopedia.com/"
' targurl = "http://tumblr.com/"
' desturl = "https://www.tumblr.com/" ' redirection if you are not login
' desturl = "https://www.tumblr.com/dashboard" ' redirection if you are login
completed = false
ie.navigate targurl
do until completed
wscript.sleep 100
loop
' your code here
msgbox ie.document.getelementsbytagname("*").length
ie.quit
sub ie_documentcomplete(byval pdisp, byval url)
if url = desturl then completed = true
end sub
Do ... Loop
that you've shown? – BelieveDo While oIE.ReadyState = 4: WScript.Sleep 100: Loop
. So first step is to wait until the "navigaiting begins", and second - until it to be completed. – BelieveBusy
. The code is running too fast and hits your loop before IE has the chance to become busy, so therefore it bypasses the loop since it's technically not busy. Very intelligent look into the answer, one that I would have never even considered. – Tarsuss