Is this possible to click on the button "detailed" using AppleScript (Google chrome)


I would usually use this for a click


but in this situation I'm not sure how to proceed

update : I updated my reply as I didn't realised the code was hided by askdifferent text editor

that what I usually use :

tell application "Google Chrome"
    tell tab 4 of window 1 to set myClickingbutton to execute javascript "document.getElementById('Clasenamehere').click();
end tell
| improve this question | | | | |
  • Could you provide a sample of the entire script? – drivec Mar 23 '18 at 15:02
  • execute front window's tab 1 javascript "document.getElementsByName('namehere')[0].click();" – Kevin Mar 23 '18 at 15:08
  • What is the URL of the page you are trying to action the button on, and which button is it? – user3439894 Mar 23 '18 at 16:38

So you already know the JavaScript method for clicking on an HTML element using its class name as a selector:


where [0] denoted the first item in the array of elements, all of whom share the same classname. Often, it's better--at least in my mind—to try and use an element's id, which provides a unique attribute by which to select an element:


To run this code from Google Chrome by way of AppleScript, the general form looks like this:

    set js to "document.getElementsByClassName('classnamehere')[0].click();"

    tell application "Google Chrome" to tell ¬
        the front window to tell ¬
        the active tab to ¬
        set jsResult to execute javascript js

The important feature about execute javascript is that it must be directed to a specific tab in Google Chrome. You can't send the command to a window or the application object. So:

    tell application "Google Chrome" to ¬
        execute javascript js

will throw an error (even on the assumption that you had defined js).

The syntax can also take this form:

    tell application "Google Chrome" to tell front window to ¬
        set jsResult to execute of tab 1 javascript js

or this form:

    tell application "Google Chrome" to tell front window to ¬
        (execute javascript js) in front tab

In each of these commands, the javascript is being told to execute in a specific tab.

You haven't yet specified what "detailed" refers to, and when you do, I can update this answer accordingly. Working on the assumption that it's either a class name or an id of an HTML element, you can use one of the expressions at the top and plug it straight into the code examples I gave you. So, you might use the JavaScript method getElementsByClassName, which would take this form:


where [0] could end up being changed to [1], [2], etc. depending how many other elements have this class name. What I would then do is define my AppleScript variable js to hold the JavaScript command for me:

    set js to "document.getElementsByClassName('detailed')[0].click();"

then tell the active tab in Chrome to execute it:

    tell application "Google Chrome"
        tell active tab of window 1 to ¬
            execute javascript js
    end tell

The execute command will always return a value, even if it's just an empty string. Therefore, if you wish, you can assign that value to a variable in AppleScript to use later in your script:

    set jsResult to the result

Or, more directly:

    set jsResult to execute javascript js
| improve this answer | | | | |
  • Thank you for the detailed answer, I updated my question because I didn't realised that the button name was hidden, however I approved your answer as I think there is no solution to my request due to the part encrypted name and also , even if my usually click snipped work, your seems way more clean and appropriate – Kevin Mar 24 '18 at 13:52
  • Thanks. If you're willing to share the URL, I could take a look and see if there's a way to do it. – CJK Mar 24 '18 at 14:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .