skip to Main Content

I want to click all the buttons at a website but my code tries to click all 2000 buttons at the same time and because of that chrome fails. How can I make it click one by one to the all buttons so it won’t force the computer and chrome? I’ve thinked to count the index of the elements and have a for loop but I wonder is there any other ways or a basic code



const divs =
document.querySelectorAll('.wbloks_1');

divs.forEach(div => {

  div.click();

});

Chrome failed because of the overload

2

Answers


  1. You can use recursion for the task

    clickButton = (index) => {
      while(index < 2000) {
      document.querySelector('.wbloks' + [index]).click();
      clickButton(index + 1);
     }
     return;
    }
    
    
    ----------
    
    
    
    Login or Signup to reply.
  2. In case you haven’t figured this out yet, and as I mentioned in my comment you could use setTimeout for this.

    const divs = document.querySelectorAll('.wbloks_1');
    const ms = 10; // whatever delay value you want
    
    divs.forEach((div, index) => {
      setTimeout(() => { div.click(); }, index*ms);
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search