问题描述
在继续执行脚本之前,如何等待网页完全加载?
How do you wait for a webpage to fully load before proceeding the script?
我知道如果希望延迟4秒,可以使用延迟4,但这还不够安全.
I know you can use delay 4 if you would want it to wait 4 seconds but this is not safe enough.
在VBA中,您有一个始终有效的简单代码,它像这样:
In VBA you have a simple code that always works and it goes like this:
Dim x As String
x = "https://na6.salesforce.com/p/attach/NoteAttach?pid=" & Range("T34").Value & "&parentname=" & Range("T35").Value & "&retURL=%2F0018000000sKz8K%3Fpb0%3Dtrue"
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate (x)
IE.Visible = True
SetParent IE.Hwnd, Application.Hwnd
Do
DoEvents
Loop Until IE.READYSTATE = 4
在Mac上使用带苹果浏览器的Safari相当于什么?
What would be the equivalent of this on mac with safari for applescript?
我在网络上看到了许多版本,但只有与延迟类似的变通方法,或者是需要指定的值来返回或计算页面上的单词数,等等.
I´ve seen many versions on the net but only workarounds similar to the delay or for a specify value to return or to count words on the page and so on.
我只是想要上面的版本是100%完美的.
I simply want the above version which is 100% perfect.
先谢谢您:)
推荐答案
您可以通过从Safari或Chrome调用"document.readyState"来访问页面的就绪状态.
You can access the ready state of a page by calling "document.readyState" from either Safari or Chrome.
tell application "Safari"
if not (exists document 1) then reopen
tell current tab of window 1 to set URL to "https://stackoverflow.com/questions/24500011/how-to-wait-for-webpage-to-fully-load-before-proceeding-script"
set the_state to missing value
repeat until the_state is "complete"
set the_state to (do JavaScript "document.readyState" in document 1)
log "busy"
delay 0.2
end repeat
log "complete"
end tell
这篇关于如何在继续执行脚本之前等待网页完全加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!