• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How do I pause a script to allow a webpage to load and then resume the script?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: How do I pause a script to allow a webpage to load and then resume the script?
      • From: DeNigris Sean <email@hidden>
References: 
 >Re: How do I pause a script to allow a webpage to load and then resume the script? (From: DeNigris Sean <email@hidden>)

  • Prev by Date: Re: Application Bundle won't quit at Shutdown
  • Next by Date: Re: How to get all layer (even in layer sets) in Photoshop
  • Previous by thread: Re: How do I pause a script to allow a webpage to load and then resume the script?
  • Next by thread: Re: How do I pause a script to allow a webpage to load and then resume the script?
  • Index(es):
    • Date
    • Thread