2

Here is the button I would like AppleScript to click :

<button class="btn btn-primary" autofocus="" ng-click="ok()" tabindex="0">OK</button>

Here is my code :

tell application "Google Chrome"
    delay 3
    execute front window's tab 1 javascript "document.getElementsByClass('btn btn-primary')[0].click();"
end tell

However the script is returning a missing value and the button remain unpressed.

Any idea how can that be done? cheers.

  • Browsers won’t let you trigger the click event via JavaScript. For details, see stackoverflow.com/a/10143157/990363. – kopischke Feb 24 '17 at 20:10
  • Chrome ? Cause I have the same working with safari , but to be fair it's only working when the windows is focused – Kevin Feb 24 '17 at 20:28
  • Possibly – different browser JavaScript security models are not really something I want to spend too much time thinking about, I have bad enough headaches as it is ;). – kopischke Feb 24 '17 at 21:22
  • Do you have a link? – adayzdone Feb 27 '17 at 7:47
  • document.getElementsByClass is not a function. document.getElementsByClassName is. Making that substitution worked perfectly for me. – aaplmath Mar 12 '17 at 22:47

You must log in to answer this question.

Browse other questions tagged .