Re: How do I pause a script to allow a webpage to load and then resume the script?
Re: How do I pause a script to allow a webpage to load and then resume the script?
- Subject: Re: How do I pause a script to allow a webpage to load and then resume the script?
- From: "Stockly, Ed" <email@hidden>
- Date: Mon, 14 Dec 2009 11:42:46 -0800
- Thread-topic: How do I pause a script to allow a webpage to load and then resume the script?
Title: Re: How do I pause a script to allow a webpage to load and then resume the script?
IMHO, there are no really good solutions to this issue.
The _javascript_ solution was really intended for this purpose, and several things could happen: the page could bounce to an error page; a popup window could interfere; a poorly written page element could (in an ad, for example) could prevent the status from ever being “complete”
Sean’s solutions are good in the cases and for the pages they’re designed to work on, but may not be applicable in many situations.
ES
On 12/14/09 8:18 AM, "DeNigris Sean" wrote:
tell application "Safari" to set docLoadingState to do _javascript_ "document.readyState" in document 1
The above will work... sometimes
I prefer either of the following techniques (add a timeout check to avoid an infinite loop)
#1: wait until whatever you need to interact with exists
Example:
tell application "Safari"
make new document with properties {URL:"http://www.google.com/"}
end tell
activate application "Safari"
tell application "System Events"
tell process "Safari"
- wait for element to exist
repeat until (text field "Google Search" of group 5 of UI element 1 of scroll area 1 of group 3 of window "Google" exists)
end repeat
- perform action
set value of text field "Google Search" of group 5 of UI element 1 of scroll area 1 of group 3 of window "Google" to "ford"
end tell
end tell
#2 just keep trying to do what it is I want to do after the page loads until it's successful (actions with side effects may be an issue e.g. submitting a transaction multiple times)
Example:
tell application "Safari"
make new document with properties {URL:"http://www.google.com/"}
end tell
-- keep trying to perform the action until it works
repeat
try
activate application "Safari"
tell application "System Events"
tell process "Safari"
set value of text field "Google Search" of group 5 of UI element 1 of scroll area 1 of group 3 of window "Google" to "ford"
click button "Google Search" of group 5 of UI element 1 of scroll area 1 of group 3 of window "Google"
end tell
end tell
-- continue with next step if it worked (in this case, meaning we didn't get an error)
exit repeat
end try
end repeat
end repeat
Good luck!
Sean DeNigris
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden