Instantly share code, notes, and snippets.

Embed
What would you like to do?
find a bunch of stuff on the page and click on them
var divs = document.querySelectorAll('.button'); [].forEach.call(divs, function(div) { div.click();});
@eviltester

This comment has been minimized.

Owner

eviltester commented Aug 16, 2018

  1. Use the dev tools to view the dom
  2. Use 'find' to create a css selector that matches all the things you want to click on
  3. Change the '.button' in the gist to the css selector you created
  4. Enter the Javascript into the console
  5. Hopefully everything you wanted clicked, is now clicked

Iteration pattern from:

https://css-tricks.com/snippets/javascript/loop-queryselectorall-matches/

MDN Click

https://developer.mozilla.org/en-US/docs/Web/Events/click

Alternative click approaches:

https://stackoverflow.com/questions/2381572/how-can-i-trigger-a-javascript-event-click

@eviltester

This comment has been minimized.

Owner

eviltester commented Aug 16, 2018

I've also used the same approach in an interval to banish adverts that are on the page and continue to appear in 'infinite scroll pages'

e.g.

setInterval(function(){
var advert = document.querySelector(".dismiss-advert");
if(advert){advert.click();}
},200);
@eviltester

This comment has been minimized.

Owner

eviltester commented Oct 8, 2018

a 'for' loop version would be:

var divs = document.querySelectorAll('.button');
for (x = divs.length - 1; x >= 0; x--) {
   divs[x].click();
}
@eviltester

This comment has been minimized.

Owner

eviltester commented Oct 11, 2018

For loop which doesn't work in reverse:

var divs = document.querySelectorAll('input.toggle');
for (x = 0; x < divs.length; x++) {
   divs[x].click();
}

Working in reverse can be useful when you are 'deleting' or the length changes over time, here my action doesn't change the length so I can start at the top and work down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment