• 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: DeNigris Sean <email@hidden>
  • Date: Mon, 14 Dec 2009 11:18:00 -0500

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

  • Follow-Ups:
    • Re: How do I pause a script to allow a webpage to load and then resume the script?
      • From: "Stockly, Ed" <email@hidden>
  • Prev by Date: Re: Modified "modification date" [Solved... almost]
  • Next by Date: Re: Application Bundle won't quit at Shutdown
  • Previous by thread: Re: Modified "modification date" [Solved... almost]
  • 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