I haven\'t ever done much with AppleScript, but I\'m trying to automate this process. I have a website with a Button that needs to be clicked. However the button is implemen
Most browsers will ignore direct calls to the click event handler, it seems (apparently for security reasons – don’t get me started on the JavaScript security model in browsers), so your click()
call just does nothing at all. You can trigger the click event via JavaScript’s event dispatching mechanism (see this question and answer of mine). However, if the site you target already does include jQuery, all you need to do is:
tell application "Safari"
do JavaScript "$('#divIdOfButton .divClassOfButton').click();" in front document
end tell
If there are several buttons of the class in your DIV
, you’ll need to add a filter expression, i.e.
tell application "Safari"
do JavaScript "$('#divIdOfButton .divClassOfButton :equ(0)).click();" in front document
end tell
but you will lose the performance advantage of querySelectorAll
leveraged by jQuery without this (see jQuery API docs).
Tested by triggering the inbox dropdown on Stack Overflow sites in Safari.