Failproof等待IE加载 [英] Failproof Wait for IE to load

查看:220
本文介绍了Failproof等待IE加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

脚本是否有一种万无一失的方式等待Internet Explorer完全加载?

Is there a foolproof way for the script to wait till the Internet explorer is completely loaded?

两者 oIE.Busy 和/或 oIE.ReadyState 的运作方式不正常:

Both oIE.Busy and / or oIE.ReadyState are not working the way they should:

Set oIE = CreateObject("InternetExplorer.application")

    oIE.Visible = True
    oIE.navigate ("http://technopedia.com")

    Do While oIE.Busy Or oIE.ReadyState <> 4: WScript.Sleep 100: Loop  

    ' <<<<< OR >>>>>>

    Do While oIE.ReadyState <> 4: WScript.Sleep 100: Loop

还有其他建议吗?

推荐答案

尝试这个,它帮助我解决了IE的类似问题:

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:向下钻取IE事件我发现 IE_DocumentComplete 是页面前的最后一个事件实际上准备好了。因此,还有一种方法可以检测何时加载网页(请注意,您必须指定可能与目标URL不同的确切目标URL,例如在重定向的情况下):

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

这篇关于Failproof等待IE加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆