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

Simple Applescript proving to be perplexing

I have a late 2008 Macbook Pro running Mavericks.


I am trying to write an Applescript that will go to Amazon using a predefined URL, and then click on the first search result. Afterwhich it would do other things like copying the item description, model, etc.


Since "Click at" is broken in Mavericks and I don't feel my MBP would run very well with Yosemite I am trying to work around this limitation.


I have tried a number of scripts I found online, with none of them working, I think perhaps because I am not supplying the correct information to the script.


Below is the URL. The script will be executed upon this page being displayed.


http://www.amazon.com/s/ref=nb_sb_noss/181-3295288-5200969?url=search-alias%3Dap s&field-keywords=071641042681


On that page I need it to click the first result's link, taking it to the details page...when I use "Inspect element" on the link I get the following:


User uploaded file

I have tried scripts like this:


tell application "Safari"

activate

do JavaScript "document.getElementByClass('a-link-normal s-access-detail-page a-text-normal').click()" in document 1

end tell

Which results with:

User uploaded file

And I also tried:

tell application "Safari"

activate

do JavaScript "document.getElementById('result_0').click()" in document 1

end tell

Which gives me:


User uploaded file


What am I doing wrong? Any help would be greatly appreciated!

MacBook Pro (15-inch Late 2008), null

Posted on Aug 31, 2015 3:24 PM

Reply
Question marked as Best reply

Posted on Sep 1, 2015 7:36 AM

Hi,


You need to get the first 'a' element.


tell application "Safari"

activate

do JavaScript "document.getElementById('result_0').getElementsByTagName('a')[0].click()" in document 1

end tell

2 replies

Simple Applescript proving to be perplexing

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