Is this possible to click on the button "detailed" using AppleScript (Google chrome)
for="7cd6f428-1are-41f2-9054-c452d7fe242-view-selector-e5f5de50-634a-45bc-bf30-98e2a64676cc">Detailed
I would usually use this for a click
"document.getElementsByName('clasenamehere')[0].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
Best Answer
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'sid
, 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:
The important feature about
execute javascript
is that it must be directed to a specifictab
in Google Chrome. You can't send the command to awindow
or theapplication
object. So:will throw an error (even on the assumption that you had defined
js
).The syntax can also take this form:
or this form:
In each of these commands, the
javascript
is being told to execute in a specifictab
.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 anid
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 methodgetElementsByClassName
, 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 variablejs
to hold the JavaScript command for me:then tell the
active tab
in Chrome to execute it: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:Or, more directly: