Help debugging AppleScript to click on webpage link

I am trying to automate the downloading of game records which are stored on successive pages on a website.

I've written the following AppleScript (see below).  It presently correctly opens a sample page (I will try later to add a loop do have this script iterate through multiple pages) but does not succeed in 'clicking' on the 'Select All' link.

I've tried inspecting the element 'Select All' and to use it's id in a Javascript command to automatically click on it (see line:  execute javascript "document.getElementById('a#c17').click()" )  but the element Select All doesn't get 'clicked'.

Since you don't have the user credentials to login to the page in question, I'm attaching a screengrab showing the info for inspect element:  Select All.

I'm not sure how to correctly specify the link 'Select All' in my AppleScript or if I'm using the correct Javascript syntax to click on it.

Thx

Script to Debug:

-- Set Counter
set Counter to 1

-- Set pageURL
set pageURL to "http://www.chess.com/home/my_archive?sortby=&show=live_bullet&color=all&result=all&page=" & Counter
display dialog Counter giving up after 1

-- Open webpage and click on 'Select All' link
tell application "Google Chrome"
      activate
      open location pageURL
      activate
      execute javascript "document.getElementById('a#c17').click()"
end tell
Inspection-of-element-SelectAll.png
qengAsked:
Who is Participating?
 
qengConnect With a Mentor Author Commented:
Thanks for getting back Kyle.

I was able to get a script working in Safari by changing the line:

do JavaScript "document.getElementById('c17').click()"

to

do JavaScript "document.getElementById('c17').click()" in current tab of first window

I'll work with that for now.
0
 
Kyle HamiltonData ScientistCommented:
provide only the name of the id
"document.getElementById('c17').click()"
0
 
qengAuthor Commented:
Kyle, thanks for your reply.  Unfortunately I still get a 'missing value' error.  See script's events and replies below:

tell application "AppleScript Editor"
      display dialog 26 giving up after 1
            --> {button returned:"", gave up:true}
end tell
tell application "Google Chrome"
      activate
      open location "http://www.chess.com/home/my_archive?sortby=&show=live_bullet&color=white&result=won&page=26"
      activate
      activate
      open location "http://www.chess.com/home/my_archive?sortby=&show=live_bullet&color=white&result=won&page=26"
      activate
      execute current application javascript "document.getElementById('c17').click()"
            --> missing value
end tell
Result:
missing value
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
qengAuthor Commented:
I had read somewhere that Google Chrome doesn't support AppleScript drive Javascript ... unsure if that is true.  In any case, I don't have any better success running the following AppleScript using Safari (although changing 'execute' to 'do' for Safari seems to run without the missing value error, though the 'Select All' link still doesn't get activated on the webpage:

-- Set Counter
set Counter to 26

-- Set pageURL
set pageURL to "http://www.chess.com/home/my_archive?sortby=&show=live_bullet&color=white&result=won&page=" & Counter
display dialog Counter giving up after 1

-- Open webpage and click on Select All link
tell application "Safari"
      activate
      open location pageURL
      activate
      delay 5
      do JavaScript "document.getElementById('c17').click()"
end tell

The script's events and replies are as follows:

tell application "AppleScript Editor"
      display dialog 26 giving up after 1
            --> {button returned:"", gave up:true}
end tell
tell application "Safari"
      activate
      open location "http://www.chess.com/home/my_archive?sortby=&show=live_bullet&color=white&result=won&page=26"
      activate
      do JavaScript "document.getElementById('c17').click()"
end tell
0
 
qengAuthor Commented:
Even getting a script which will work in google chrome to target a click on a link would be a start.  We could then see if it can be adapted to work in the situation I'm trying to get working.
0
 
Kyle HamiltonConnect With a Mentor Data ScientistCommented:
say you have an element:

<a href="#" id="someId">a link</a>

Open in new window


the following line triggers a click on the element.

document.getElementById('someId').click()

Open in new window


This works in chrome.
0
 
qengAuthor Commented:
Kyle, still not working. I can get the script to run in Safari but it generates a Missing Value error.  With Chrome, the script generates a syntax error.  

As an aside which is the 'correct' syntax for Chrome (I've tried all three; none are working):

a)  document.getElementById('c17').click()
b)  do JavaScript "document.getElementById('c17').click()"
c)  execute Javascript "document.getElementById('c17').click()"

See attached screen grabs for the Safari and Chrome errors.

Could this be an AppleScript, OS, or Browser version issue?

I run AS Version 2.4.3 (131.2) , OS X Lion 10.7.5 (11G63), Chrome Version 39.0.2171.95 (64-bit)
Safari-works-but-MissingValue.png
Chrome-Syntax-Error-w-Do.png
Chrome-Syntax-Error-w-Execute.png
0
 
Kyle HamiltonData ScientistCommented:
hi qeng,

you should request attention for your question. i'm not able to help you with the apple script piece
0
 
qengAuthor Commented:
Wasn't able to get script working in Chrome but managed to eventually get my own script working in Safari.  I don't see how to assign partial points for solutions.
0
All Courses

From novice to tech pro — start learning today.