Javascript code
var inputs = document.getElementsByClassName('_42ft _4jy0 FriendRequestAdd addButton _4jy3 _517h');
for(var i=0; i<inputs.length;i++) {
inputs[i].click();8
}
How do I add a one second delay in the loop?
Javascript code
var inputs = document.getElementsByClassName('_42ft _4jy0 FriendRequestAdd addButton _4jy3 _517h');
for(var i=0; i<inputs.length;i++) {
inputs[i].click();8
}
How do I add a one second delay in the loop?
You could use the setTimeout
method, something like this should work. What setTimeout
does is execute the code after the amount of ms specified as a second argument. In this case we use closures to make sure we pass in the right index when the function gets called, otherwise you end up calling the click()
on the same value of i
for every call.
for(var i=0; i<inputs.length; i++){
(function(index) {
setTimeout(function() { inputs[index].click(); }, 1000);
})(i);
}
Edit: You should probably provide more info on what you're final goal is and why you need this specific functionality. There might be different approaches that don't require to add a delay like the one proposed in this answe and request from you.