Reputation: 1904
How can I simulate exact behave of mouse click on a browser's button (e.g. Firefox)?
When user clicks on a button using mouse click then an event is generated. Could I use or call the event manually?
I can use Javascript to simulate click on a button but it will not call the same event in the same way as when a user really clicks on the button.
The reason I ask for solution: record engine for recording any event occur in the document level works in background, I want to create web app with self play functionality, that means when I browse the web app in browser it will do business flow automatically and then the engine will record the events.
Please ask if my question not clear, Thanks.
Upvotes: 1
Views: 4921
Reputation: 54640
You should look into Selenium. It uses automation and other native APIs to simulate user input in exactly the way you wish.
Upvotes: 0
Reputation: 34596
This is easiest with something like jQuery.
//listen for clicks - real or simulated
$('#some_element').on('click', function() { alert('click!'); });
//simulate clicks (two ways)
$('#some_element').click();
$('#some_element').trigger('click');
It is possible to know, from inside the event callback, whether the event was real or simulated. I did a blog post on this some months ago.
Upvotes: 1