admin管理员组文章数量:1384482
I need to now how to fire a mouse click event on a button automatically. I have this but doesn't work :(
window.setInterval(function() { simulateClick(); }, 2000); function simulateClick() { var evt = document.createEvent("MouseEvents"); evt.initMouseEvent("click", false, false, window, 0, 684, 571, 684, 508, false, false, false, false, 0, null); var a; a.dispatchEvent(evt); }
Thanks in advance
Oscar
I need to now how to fire a mouse click event on a button automatically. I have this but doesn't work :(
window.setInterval(function() { simulateClick(); }, 2000); function simulateClick() { var evt = document.createEvent("MouseEvents"); evt.initMouseEvent("click", false, false, window, 0, 684, 571, 684, 508, false, false, false, false, 0, null); var a; a.dispatchEvent(evt); }
Thanks in advance
Oscar
Share Improve this question edited May 6, 2011 at 20:50 locrizak 12.3k12 gold badges62 silver badges80 bronze badges asked May 6, 2011 at 20:46 OscarOscar 311 gold badge1 silver badge2 bronze badges 3- My guess is that you're not initiating a. IT just says "var a;" but you never specify which element it is. Other than that I think it looks fine. – Mamsaac Commented May 6, 2011 at 20:56
- If you want to simulate for testing purposes you can use selenium seleniumhq – ariel Commented May 6, 2011 at 21:12
- Looks like you're trying to do this: stackoverflow./questions/6157929/… – Nate Commented Jan 7, 2014 at 19:55
2 Answers
Reset to default 2If all you want to do is click a button, button elements have a click
method that can be invoked:
<input type="button" id="theButton" onclick="javascript:alert('The button was clicked!');" value="A button" />
<script language="javascript">
setTimeout(function(){
document.getElementById("theButton").click();
}, 1000); // wait one second then click the button
</script>
There's no need to "actually" simulate the mouse click at a specific x,y position.
I dont know if its posible to do that on javascript but if you need automatic and periodic clicks maybe you can do that with external tools like autohotkey
本文标签: javascript simulate mouse click on specific positionStack Overflow
版权声明:本文标题:javascript simulate mouse click on specific position - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744529023a2610917.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论