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

How to click a button in chrome using applescript?

I know it's website specific, but i'm just having a hard time understanding exactly how the do Javascript function works. For example, say I have this site to vote on and i wanted to run an apple script to basically over vote and make a specific contestant win, how exactly would i run the script (if we forget vote limits due to cookies/ip tracking etc). For example http://www.kraveradio.net/gallery.html is having a voting contest. So if i inspected the element for SUs it says the thumbs up is "i class="rw-ui-like-icon"></i". How would i make sure I get the button for Sus (or a specific contestant) and what would the code be for the button?



I'm familiar with python and not javascript so i'm a little lost! Sorry for the site being NSFW it was the best example i could find!


repeat 1 times

tellapplication "Chrome" toopen location "http://www.kraveradio.net/gallery.html"


delay 3


do JavaScript "document.getElementsByClassName('<i class="rw-ui-like-icon"></i>')[0].click()" in document 2

delay 5

end tell

end repeat

MacBook Air, OS X Mavericks (10.9.2)

Posted on Apr 15, 2014 1:52 PM

Reply
2 replies

Apr 15, 2014 11:19 PM in response to Cravenater

I loathe Javascript, so probably can't nail this directly, but I can tell you your JS is invalid.


Given an HTML entity:


<img class="rw-ui-like-icon">


You would reference that object using the class name only, not the entire HTML tag, e.g.:


document.getElementsByClassName('rw-ui-like-icon'>


So I'd start there. That said, though, it may not be the full answer to your question. Ordinarily, clicking on an image has no effect. There has to be some action (either a form submit or JavaScript) attached to it that feeds back to the server. That's the component you need to find.


Oh, and just for the record, if I were the one running the contest/survey/whatever, and found someone trying to game the system like this, I'd probably discard all votes for that option. Just sayin'

Apr 16, 2014 10:18 AM in response to Camelot

Yea i'm just curious exactly how to run a script where you would select a specific thing on a page. Unfortunately i'm familar with Python but have no javascript knowledge so i'm kind of lost. I recently found out about applescript and figured it would be interesting to implement!


If you just did the class name how would you prevent it from choosing all the "like" buttons since they are all the same rw-ui-like-icon?

How to click a button in chrome using applescript?

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