How to check all checkboxes on a web page from the browser console.

How to check all checkboxes on a web page from the browser console.

Some of us may get frustrated with the large number of checkboxes that need to be clicked to proceed to the next page. This is particularly frustrating during testing, as it must be done repeatedly, consuming time and affecting productivity. Fortunately, we can address this issue from the browser console. Here’s how you can do it:

Step 1 - Open the Web Page

Navigate to the web page containing the checkboxes you need to check.

web page contains 100 check boxes


In the picture above, there are 100 checkboxes. Normally, I would have to click on each checkbox individually, which would require 100 clicks to select all the checkboxes on the page.

We can select all these checkboxes without having to click on each one individually.

Step 2 - Open the Browser Console

Press F12 or right-click on the page and select "Inspect," then go to the "Console" tab.

Copy paste the below code in the console tab

const inputs = document.querySelectorAll('input[type="checkbox"]');

for (let i = 0; i < 49; i++) {

  setTimeout(function() {
    inputs[i].click()
  })};

        
After pasting the code in the console tab


Step 3 - Run the Script

To run the script, simply press Enter key, and the code will automatically execute and check all the checkboxes for you

Page response after pressing Enter key



Also please keep it in mind:

This code assumes there are at least 100 checkboxes on the page. If there are fewer, it will throw an error.

The "setTimeout" function is used here to ensure that clicks are executed in quick succession but not all at once, which can be useful to avoid potential issues with too many simultaneous actions. However, without specifying a delay, the actual impact might be minimal.

If the intent is to click all checkboxes with no delay, you could simplify the code by removing "setTimeout" :

const inputs = document.querySelectorAll('input[type="checkbox"]');

for (let i = 0; i < inputs.length; i++) {

  inputs[i].click();

}        
Morten M?hre

Professional translator, consultant, editor and writer

3 个月

Nope... Almost half of the boxes were checked in Firefix, but far from all (175 total). For Chrome, an error is returned: VM657:6 Uncaught TypeError: Cannot read properties of undefined (reading 'click') ???at <anonymous>:6:15

赞
回复

要查看或添加评论,请登录

Jithin Somaraj的更多文章

  • How to Perform Data-Driven Testing in Postman?

    How to Perform Data-Driven Testing in Postman?

    Data-driven testing is a smart way to test software by running tests with different sets of data. Postman, a popular…

  • How To Generate Individual HTML Report in OWASP ZAP

    How To Generate Individual HTML Report in OWASP ZAP

    When scanning multiple APIs simultaneously in OWASP ZAP, many users find it challenging to generate individual API…

    1 条评论
  • How to load external JavaScript file in JMeter

    How to load external JavaScript file in JMeter

    In certain situations, such as during payment processes or when submitting forms within the application, front-end…

    1 条评论
  • How do they Do It ?!!!!

    How do they Do It ?!!!!

    Today I want to share you about how much efforts it takes to hack your device for intruders Because of there is a…

  • How To Set Up Swagger UI editor Locally in Windows

    How To Set Up Swagger UI editor Locally in Windows

    This was one I have searched a lot more but couldn't find a simple answer fortunately I had time to find it out so that…

    7 条评论
  • Appium Android Automation Starter

    Appium Android Automation Starter

    Introduction Appium is an Open-source tool which can be used to automate mobile and desktop applications. Appium…

  • An Introduction to Kali Linux

    An Introduction to Kali Linux

    Kali Linux is an operating basically an operating system which is based on linux.As per Wikipedia, Kali Linux is a…

  • Different Doors In Apache JMeter

    Different Doors In Apache JMeter

    First of all this is my first ever article in the Linked in community. And I want to inform you that I'm not…

社区洞察

其他会员也浏览了