Reputation: 2458
I'm playing with the writing of an implementation of the JSONWire Protocol. The implementation simulates user behaviour (click, navigate, etc.)... my goal is to make a lighter (albeit less feature complete) version of th selenium server.
Now I've noticed that when simulating events (for instance, a click), the document.activeElement
property does not change.
I've made this JSfiddle to demonstrate: http://jsfiddle.net/75bq50wa/6/.
You should notice that if you click the "Click me" checkbox, the activeElement
changes, whereas it does NOT change when clicking using Javascript.
My interpretation is that only native events alter the state of the activeElement
property.
Is this correct, or is there a way to better emulate user events in Javascript?
Upvotes: 1
Views: 54
Reputation: 7799
The W3C Recommendation (http://www.w3.org/TR/html5/editing.html) says:
document . activeElement
Returns the currently focused element.
This means, you need to additionally focus() the element, in order to correctly simulate a User's click.
See this updated JSFiddle: http://jsfiddle.net/e3vg5k75/
Upvotes: 1