qeng
asked on
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
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('
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('
end tell
Inspection-of-element-SelectAll.png
ASKER
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').clic k()"
--> missing value
end tell
Result:
missing value
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('
--> missing value
end tell
Result:
missing value
ASKER
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').clic k()"
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').clic k()"
end tell
-- 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('
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('
end tell
ASKER
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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('c 17').click ()
b) do JavaScript "document.getElementById(' c17').clic k()"
c) execute Javascript "document.getElementById(' c17').clic k()"
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
As an aside which is the 'correct' syntax for Chrome (I've tried all three; none are working):
a) document.getElementById('c
b) do JavaScript "document.getElementById('
c) execute Javascript "document.getElementById('
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
hi qeng,
you should request attention for your question. i'm not able to help you with the apple script piece
you should request attention for your question. i'm not able to help you with the apple script piece
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
"document.getElementById('