script to click a button on a site

in Script development
Subscribe to script to click a button on a site 2 posts, 2 voices



dpace32 User
FirefoxMacintosh

Hello -

First time script writer, long time Greasemonkey lover and I have a question already...

I am trying to modify the script below to click a button that looks like this on a site:

<button>check price</button>

I am using this template... so far the page seems to keep reloading... nothing else happening. Any advice to someone new?

Thanks!

(function() {
window.addEventListener("load", function(e) {clickConfirmButton()}, false);
})();


function clickConfirmButton () {
var buttons = document.getElementsByTagName('button');
var clicked = false;

for (var index=0; (index<buttons.length);>
if(buttons[index].value=="check price"){
buttons[index].click();
clicked = true;
break;
}
}

if(!clicked){
setTimeout("window.location.reload()",300*1000);
}
}

 
Jefferson Scher Scriptwright
FirefoxWindows

Does this work?

function clickConfirmButton(e) {
 var buttons = document.getElementsByTagName('button');
 var clicked = false;
 for (var index=0; index < buttons.length; index++){
  if(buttons[index].textContent == "check price"){
   buttons[index].click();
   clicked = true;
   break;
  }
 }
 if(!clicked){
  setTimeout("window.location.reload()",300*1000);
 }
}
clickConfirmButton();

Main change is from button.value to button.textContent.