My goal is to determine whether or not an element is on a page and perform an action on that element, if it exists.
In this code, I'm only showing the second part of trying to perform an action on an element.
My code is:
tell application "Safari"
open location "http://www.apple.com"
tell front document
do JavaScript "document.getElementById(\"gn-store\").click()"
end tell
end tell
However, I always get a result of "missing value", from this code and similar things I've tried (including calling a function in Js, to return a value from getElementById( ).
I don't understand what I'm doing wrong. I've been at it for hours. (and for the record, I am an applescript noob).
I find Chrome reacts better to Javascript via AppleScript...
tell application "Google Chrome"
if not (exists window 1) then reopen
activate
tell window 1 to tell active tab
set its URL to "http://www.apple.com/"
delay 3
execute javascript "document.getElementById('gn-store').childNodes[0].click()"
end tell
end tell
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With