Skip to main content
blog title image

3 minute read - Exploratory Testing JavaScript

Click bots for social media and beyond

Aug 21, 2018

TLDR: simple click bots from the JavaScript console can make social media and other sites easier to use

I have been using click from the JavaScript console more to: fill in forms, remove ads, remove popups, etc. In this post I explain the general principles.

I wrote a Gist recently to document some patterns I’ve been using in the real world.

I’ve used the patterns in the above gist to:

  • have a ‘bot’ running which closes down adverts that appear when I scroll through the feed of various social media sites
  • click on 100+ items on a page to sign up to stuff
  • remove popups as I scroll through a site
  • etc.

The more we automate our normal life, the more it becomes normal to automate tactically as we test.

Rather than explain how to remove ads on a social media site and potentially get myself kicked off, I’m going to explain using the todoMvc application.

Test Data Required

Using: http://todomvc.com/examples/backbone/

If I create a bunch of todos.

for (x = 0; x < 100; x++) {
app.todos.create(
     {title: "todo ".concat(x),
     order: app.todos.nextOrder(),
     completed: false})
}

Note: I could have asked you to do it manually, instead I’ve shown you some tactical code that you can run from the JavaScript console to create 100 todos in the application.

Toggle them all done

I can toggle all the todos with a for loop:

var divs = document.querySelectorAll('input.toggle');
[].forEach.call(divs, function(div) { div.click();});

The above code is taken from the Gist and I took the basic principle from css-tricks

This works well as a static action. Say - selecting a bunch of items in a form.

Toggle Them as a bot

If I was scrolling through a site and adverts kept popping up then I really want a bot running in the background to do the work for me.

If I want to run this as a bot then I can’t use the same css selector because it will keep toggling the first item in the list.

var tododonebot = setInterval(function(){
var todo = document.querySelector("input.toggle");
if(todo){todo.click();}
},200);

I need to be more specific and select the next one which is not completed.

li:not(.completed) > div.view > input.toggle

Then I can write a bot that will, click the next todo every 200 milliseconds.

var tododonebot = setInterval(function(){
var todo = document.querySelector("li:not(.completed) > div.view > input.toggle");
if(todo){todo.click();}
},200);

Feel free to try this

Experiment on your least favourite social media site that keeps showing you stuff.

Right click and inspect the things you don’t like, and add whatever action it takes to remove them into your bot.

Build this type of thinking and experimentation into your daily life and your ability to automate from the console will improve.

I have added a video version showing this in action and explaining it in more detail as a Patreon.com/eviltester video.

If you are a Patron you can find the video here https://www.patreon.com/posts/20817713