Sends an event to the web page.
The events are not synthetic DOM events, each event is sent to the web page as if it comes as part of user interaction.
sendEvent(mouseEventType[, mouseX, mouseY, button='left'])
The first argument is the event type. Supported types are
'click'. The next two arguments are optional but represent the mouse position for the event.
The button parameter (defaults to
left) specifies the button to push.
'mousemove', however, there is no button pressed (i.e. it is not dragging).
sendEvent(keyboardEventType, keyOrKeys, [null, null, modifier])
The first argument is the event type. The supported types are:
keydown. The second parameter is a key (from page.event.key), or a string.
You can also indicate a fifth argument, which is an integer indicating the modifier key.
- 0: No modifier key is pressed
- 0x02000000: A Shift key on the keyboard is pressed
- 0x04000000: A Ctrl key on the keyboard is pressed
- 0x08000000: An Alt key on the keyboard is pressed
- 0x10000000: A Meta key on the keyboard is pressed
- 0x20000000: A keypad button is pressed
Third and fourth argument are not taken account for keyboard events. Just give null for them.
Simulate a shift+alt+A keyboard combination
var webPage = require('webpage'); var page = webPage.create(); page.sendEvent('keypress', page.event.key.A, null, null, 0x02000000 | 0x08000000);