Tampermonkey click random class or coordinates

Scorpion Ghost

Elite Member
Executive VIP
Jr. VIP
Joined
Mar 22, 2013
Messages
9,142
Reaction score
10,489
I have a page with buttons that have the same class. About 15 on the page. Say:

4545.PNG


I would like a script that will click one of them, randomly.

I looked around and tried something like this with various variations, but no luck:

7878.PNG


It would even work if it clicked random coordinates on a screen. I would insert 10 sets of coordinates, and for it to click one of them at random.

Any ideas? @reaaski
 
are you planning to execute this in the browser console? maybe i'm being ignorant here but you syntax looks off, I've rewritten it.

var links = document.querySelectorAll('.myclass'); var randomIndex = Math.floor(Math.random() * links.length); var randomLink = links[randomIndex]; randomLink.click();

still having issues drop me a message
 
Try to use JQuery to emulate user behaviour, using built-in functions, with js you can add event listener and make the same, but jquery will give you short way to do that
 
are you planning to execute this in the browser console? maybe i'm being ignorant here but you syntax looks off, I've rewritten it.

var links = document.querySelectorAll('.myclass'); var randomIndex = Math.floor(Math.random() * links.length); var randomLink = links[randomIndex]; randomLink.click();

still having issues drop me a message

That's awesome man, works perfectly. Thank you :)
 
Back
Top