PhantomjsAPI之sendEvent

随时随地阅读更多技术实战干货,获取项目源码、学习资料,请关注源代码社区公众号(ydmsq666)

from:http://phantomjs.org/api/webpage/method/send-event.html

sendEvent

Sends an event to the web page.

1.7 implementation source.

The events are not synthetic DOM events, each event is sent to the web page as if it comes as part of user interaction.

Mouse events

sendEvent(mouseEventType[, mouseX, mouseY, button='left'])

The first argument is the event type. Supported types are 'mouseup''mousedown''mousemove''doubleclick' and '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.

For 'mousemove', however, there is no button pressed (i.e. it is not dragging).

Keyboard events

sendEvent(keyboardEventType, keyOrKeys, [null, null, modifier])

The first argument is the event type. The supported types are: keyupkeypress and 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.

Examples

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);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值