Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Below is the hyperlink I’ve:

<a href="#" target="_blank" onclick="javascript:Test("Test");">MSDN</a>

I want to automate the number of clicks I’ll have on the hyperlink when I test this webpage. Can anyone tell me how I can do this?

1 Answer

0 votes
by (19.7k points)

To do a single click on an HTML element, use element.click().

To repeat the clicks, you have to add an ID to the element to uniquely select like below:

<a href="#" target="_blank" id="my-link" onclick="javascript:Test('Test');">Google Chrome</a>

In your case you can  call the .click() method in the JavaScript code via for loop like below:

var link = document.getElementById('my-link');

for(var i = 0; i < 50; i++)

   link.click();

Interested in Java? Check out this Java tutorial by Intellipaat.   

Browse Categories

...