I have a hyperlink in my page. I am trying to automate a number of clicks on the hyperlink for testing purposes. Is there any way you can simulate 50 clicks on the hyperlink using JavaScript?
<a href="#" target="_blank" onclick="javascript:Test("Test");">MSDN</a>
I'm looking for onClick event trigger from the JavaScript.
Fair warning:
element.onclick()
does not behave as expected. It only runs the code withinonclick="" attribute
, but does not trigger default behavior.I had similar issue with radio button not setting to checked, even though
onclick
custom function was running fine. Had to addradio.checked = "true";
to set it. Probably the same goes and for other elements (aftera.onclick()
there should be alsowindow.location.href = "url";
)Performing a single click on an HTML element: Simply do
element.click()
. Most major browsers support this.To repeat the click more than once: Add an ID to the element to uniquely select it:
and call the
.click()
method in your JavaScript code via a for loop: