Trying to click a button in safari I'm trying to click a button in a webpage with AppleScript, but it only seem to work 1/10 times. I copied this code,

to clickID(theId) --creates a function that we can use over and over again instead of writing this code over and over again

tell application "Safari" -- lets AppleScript know what program to controll

    do JavaScript "document.getElementById('" &amp; theId &amp; "').click();" in document 1
    do JavaScript "document.getElementById('" &amp; theId &amp; "').onclick();" in document 1
    do JavaScript "document.getElementById('" &amp; theId &amp; "').submit();" in document 1 -- performs JavaScript code that clicks on the element of a specific id

    end tell -- tells Applescript you are done talking to Safari

end clickID -- lets AppleScript know we are done with the function


I added in the .onClick() and .submit() lines because I saw them in some other code snippets and figured it might help for backup. But it didn't affect it at all. Is it a weird button or am I doing something wrong?

Thank you!
I would recommend trying Keyboard Maestro.

It has a built-in feature to "Click Safari Link" or "Click Google Chrome Link" and also has a feature to click buttons too.

If you can link to an example page, I can give more specific advice.