How to tell if Safari has finished loading a web page

Hey Jo,

Learning a little JavaScript gets your foot in the door.

Learning a lot will let you do magic.

(I have yet to learn a lot.)

Here’s an example AppleScript for filling a form and clicking a radio button:

tell application "Safari"
  tell front document
    do JavaScript "document.forms['form']['clientAcctNum'].value = '" & "<some-text>" & "'"
    do JavaScript "document.forms['form']['firstName'].value = '" & "<some-text>" & "'"
    do JavaScript "document.forms['form']['middleInitial'].value = '" & "<some-text>" & "'"
    do JavaScript "document.forms['form']['lastName'].value = '" & "<some-text>" & "'"
    do JavaScript "document.forms['form']['address'].value = '" & "<some-text>" & "'"
    do JavaScript "document.forms['form']['city'].value = '" & "<some-text>" & "'"
    do JavaScript "document.forms['form']['state'].value = '" & "<some-text>" & "'"
    do JavaScript "document.forms['form']['zipCode'].value = '" & "<some-text>" & "'"
    do JavaScript "document.forms['form']['phone'].value = '" & "<some-text>" & "'"
    do JavaScript "document.forms['form']['workPhone'].value = '" & "<some-text>" & "'"
    do JavaScript "document.forms['form']['custEmail'].value = '" & "<some-text>" & "'"
    do JavaScript "document.forms['form']['paymentAmount'].value = '" & "<some-text>" & "'"
    do JavaScript "document.getElementById('radioCreditCard').click()"
  end tell
end tell

I used Keyboard Maestro to discover the majority of the syntax, and then I Googled to refine that into something AppleScript would accept.

This particular form fills around 5 times faster with the AppleScript action than with the equivalent Safari Actions.


Best Regards,
Chris

2 Likes