How To Click Multiple Buttons At Once In Google Chrome

Let’s say: you have a page that contains single or multiple buttons that need to be accessed through one click.

To avoid doing this task repetitively for all the buttons on that page, you can write a simple JavaScript code that’ll do the job for you.

In this tutorial, we’ll have a closer look at how to use Google Chrome’s Developer Tool/Console for accessing one or more buttons on a single page and avoiding redundancy to ensure efficiency in our code.

Let’s get started!


We’ll follow a step-by-step guide to run the script using Google Chrome's Developer Console:

1. The first and foremost step is to launch the Google Chrome application. Once it’s launched, you need to open its Developer Console, and you can do this by using the following keyboard shortcut:

Ctrl+Shift+J (For Windows, Linux, Chrome OS Users)
Ctrl+Option+J (For MacOS Users)

Now Chrome’s Developer Tools are opened inside that browser tab on the right side corner and the console tab will active in it just like the following snapshot:


2. Next, you are supposed to open the page in which you need to click the multiple buttons at once. Once you have opened the page, you must follow the below-given JavaScript code that’ll make this task:

var inputs = document.getElementsByClassName('XXX'); 
for(var i=0; i<inputs.length;i++)
{ 
	inputs[i].click(); 
}

In the above-given code, you need to make a minor change based on the structure of your target page, which is “XXX” that refers to the class name(s) of the button(s) you want to click at once. There’s a simple way that’ll you the class name(s) of those buttons.

Hover your mouse and point it on the button, after that right-click on that button, and click “Inspect”.

It’ll open a tab for you containing the code for that button, you’ll be able to find the class name right there in the container just as the following snapshot:

You can check the class name through this process and replace with the “XXX” in the above-given code and then press the Enter button to run the script.


There you go!

That should do the job for you and will click the multiple buttons on that page without any extra effort.