AppleScript click on button (chrome)

document.getElementsByClassName('ng-scope')[0].click(); is perfectly fine JavaScript, but it's targeting a <span> element (which usually don't have click() events associated with them), and not the <button> element (whose class attribute has value "btn-primary").

Therefore, your JavaScript needs to target btn-primary, like so:

document.getElementsByClassName('btn-primary')[0].click();

(where [0] will possibly need to be adjusted, depending on how many other elements before this one share its class name).

Alternatively, if you're confident that the correct <span> element is identified by the index 0, then you could access its parent element (which is the <button>) and issue the click() that way:

document.getElementsByClassName('ng-scope')[0].parentElement.click();

Without access to the webpage itself, though, I'm unable to test this rigorously, so, whilst I'm confident that the JavaScript principles are sound, you may need to do some tweaks of your own to isolate the element by using the correct class name and correct array index.


It might be generating a click that you aren't capturing.

  1. Inserted your exact markup with Chrome DevTools (to this page)
  2. Added onclick="alert('!');" to the button
  3. Ran your exact script in Script Editor
  4. Got "!" alert dialog