Solved

Help debugging AppleScript to click on webpage link

Posted on 2015-01-04
9
573 Views
Last Modified: 2015-01-13
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
0
Comment
Question by:qeng
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 25

Expert Comment

by:Kyle Hamilton
ID: 40531363
provide only the name of the id
"document.getElementById('c17').click()"
0
 

Author Comment

by:qeng
ID: 40532386
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
 

Author Comment

by:qeng
ID: 40532405
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
Simple, centralized multimedia control

Watch and learn to see how ATEN provided an easy and effective way for three jointly-owned pubs to control the 60 televisions located across their three venues utilizing the ATEN Control System, Modular Matrix Switch and HDBaseT extenders.

 

Author Comment

by:qeng
ID: 40536702
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
 
LVL 25

Assisted Solution

by:Kyle Hamilton
Kyle Hamilton earned 500 total points
ID: 40536977
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
 

Author Comment

by:qeng
ID: 40538327
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
 
LVL 25

Expert Comment

by:Kyle Hamilton
ID: 40538369
hi qeng,

you should request attention for your question. i'm not able to help you with the apple script piece
0
 

Accepted Solution

by:
qeng earned 0 total points
ID: 40538514
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
 

Author Closing Comment

by:qeng
ID: 40546211
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

Featured Post

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Validating Date Part2 2 27
Use Mid in Html 6 22
Compute age Html 2 27
javascript works in Chrome, but none of the other browsers 14 35
In this article we will discuss some EI Capitan Mail app issues and provide some manual process to resolve them.
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question