How can I trigger a JavaScript event click

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

    Fair warning:

    element.onclick() does not behave as expected. It only runs the code within onclick="" 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 add radio.checked = "true"; to set it. Probably the same goes and for other elements (after a.onclick() there should be also window.location.href = "url";)

提交回复
热议问题