Search code examples
javascripthtmljquerybuttonautomation

Trying to write a script that auto-clicks the buttons on a rating page. Script works for one single element but not the whole page


I want to only click the + buttons on the page and make them increment to 4 for every table row (24 columns and 100 rows ). The buttons only appear if you click on every single sector. Complete Row

Thats how it looks when you click on it. Picture of the button (+ button)

Thats a snippet of the code which I labeled. Code Snippet

I used different scripts like this one:

<!DOCTYPE html>
<html>
<body>

<p>Hover over the checkbox to simulate a mouse-click.</p>

<form>
  <input type="checkbox" id="myCheck" onmouseover="myFunction()" onclick="alert('click event occured')">
</form>

<script>
function myFunction() {
  document.getElementById("myCheck").click();
}
</script>


</body>
</html>

And tried to inser it at a logical point but it only works for one single table element. I want the script to work on all +buttons.


Solution

  • You could select all the buttons with the class skilllevel_inc and then click 4 times on each of them. An example code would be :

    let allButtons = document.getElementsByClassName("skilllevel_inc");
    for(var i=0 ; i<allButtons.length ; i++) {
       if(allButtons[i]) {
        let j=0;
        while(j<4) {
          allButtons[i].click();
          j+=1;
        }
      }
    }