How can I trigger a JavaScript event click

后端 未结 9 2141
迷失自我
迷失自我 2020-11-22 02:56

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

9条回答
  •  醉梦人生
    2020-11-22 03:26

    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:

    Google Chrome
    

    and call the .click() method in your JavaScript code via a for loop:

    var link = document.getElementById('my-link');
    for(var i = 0; i < 50; i++)
       link.click();
    

提交回复
热议问题