How can I trigger a JavaScript event click

后端 未结 9 2049
迷失自我
迷失自我 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:31

    I'm quite ashamed that there are so many incorrect or undisclosed partial applicability.

    The easiest way to do this is through Chrome or Opera (my examples will use Chrome) using the Console. Enter the following code into the console (generally in 1 line):

    var l = document.getElementById('testLink');
    for(var i=0; i<5; i++){
      l.click();
    }
    

    This will generate the required result

提交回复
热议问题