I'm trying to click all buttons on a page with the class "btn btn-primary UnFollowUser".
Here is the script I have tried using
var buttons = document.getElementsByName('UnFollowUser');
for(var i = 0; i <= buttons.length; i++)
buttons[i].click();
But that throws the error:
VM336:5 Uncaught TypeError: Cannot read property 'click' of undefined(…)(anonymous function) @ VM336:5InjectedScript._evaluateOn @ VM158:878InjectedScript._evaluateAndWrap @ VM158:811InjectedScript.evaluate @ VM158:667
Any ideas?
You are using getElementsByName instead of getElementsByClassName
var buttons = document.getElementsByClassName('UnFollowUser');
for(var i = 0; i < buttons.length; i++)
buttons[i].click();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With