Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Clicking a “div button” on a Safari web-page using AppleScript

My goal is to use AppleScript/Safari to click several elements of an external web-site. This is working fine except for the following 3 "buttons", all created within

<div>
elements:

The "Call" button:

<divrole="button"class="goog-inline-block jfk-button jfk-button-primary jfk-button-narrow"tabindex="0"style="-webkit-user-select: none;">Call</div>

The "Text" button:

<divrole="button"class="goog-inline-block jfk-button jfk-button-primary jfk-button-narrow"tabindex="0"style="-webkit-user-select: none;">Text</div>


Note: the "Call" and "Text" elements are identical except for the tags "Call" vs "Text" at the end".

The "Send" button:

<divclass="goog-button-base-content">Send</div>

What doesn't work:

tell application "Safari"

doJavaScript"document.getElementsByClassName('ClassNameHere')[n].click();"in document 1

-- n is the element number, i.e.0or1)

end tell

This returns

missing value
suggesting that the statement didn't return anything.


The problem:

  • Some say click() will work in this setting, though it did not work as implemented above
  • Others say JQuery is needed. However, I need to use Applescript/Safari and I've read that JQuery is not natively available in this setting.


And finally, the Question:

When answering its best to assume I know nothing about Javacript/JQuery (I'm OK with AppleScript). So the best answer would provide a sample code that I can cut/paste into Applescript's

do JavaScript
command.

  1. If the above elements can be clicked via pure JavaScript (preferred), please provide a sample code.
  2. If pure Javascript is not possible, and JQuery is needed, please provide an example that illustrates how JQuery can be implemented within AppleScript (is that was done in this answer?)

Any comments that help me understand will also be appreciated. Thanks in advance!

Posted on Aug 23, 2015 5:34 PM

Reply
1 reply

Clicking a “div button” on a Safari web-page using AppleScript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.