How can I trigger a JavaScript event click

后端 未结 9 2160
迷失自我
迷失自我 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条回答
  •  Happy的楠姐
    2020-11-22 03:39

    Use a testing framework

    This might be helpful - http://seleniumhq.org/ - Selenium is a web application automated testing system.

    You can create tests using the Firefox plugin Selenium IDE

    Manual firing of events

    To manually fire events the correct way you will need to use different methods for different browsers - either el.dispatchEvent or el.fireEvent where el will be your Anchor element. I believe both of these will require constructing an Event object to pass in.

    The alternative, not entirely correct, quick-and-dirty way would be this:

    var el = document.getElementById('anchorelementid');
    el.onclick(); // Not entirely correct because your event handler will be called
                  // without an Event object parameter.
    

提交回复
热议问题