I am trying to click a simple button in safari when on a web page using applescript. I have the following code:
tell application "Safari"
activate
repeat 5 times
do JavaScript "document.all(\"Roll Again\").click()" in document 1
delay 2
end repeat
end tell
However, when I run this code, I get an error: "missing value". The event log displays the following result:
tell application "Safari"
activate
do JavaScript "document.all(\"Roll Again\").click()" in document 1
--> missing value
do JavaScript "document.all(\"Roll Again\").click()" in document 1
--> missing value
do JavaScript "document.all(\"Roll Again\").click()" in document 1
--> missing value
do JavaScript "document.all(\"Roll Again\").click()" in document 1
--> missing value
do JavaScript "document.all(\"Roll Again\").click()" in document 1
--> missing value
end tell
Could someone please tell me why the button is not being pressed and what missing value means? Is there another simpler way to achieve the button press? I can press the button using automator, however I would like to do it using AppleScript.
P.S. document is the current window in safari