CasperJS:模拟滑动事件 [英] CasperJS: Simulate swipe-event

查看:89
本文介绍了CasperJS:模拟滑动事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一些casperjs测试。到目前为止进展顺利,但一件事我失败了:

I tried to build a few casperjs tests. Went well so far but at one thing I failed:

为滑动事件构建测试。

我需要这样的东西:

casper.mouse.down("#myelement"); // press and hold mousebutton
casper.mouse.move_x(200); // Move mouse 200 to the right
casper.mouse.up(); // Release mousebutton

但是casper-docs中没有诸如move_x的功能。

But there is no function like move_x in the casper-docs.

有人有想法吗?

推荐答案

您可以轻松编写自己的move_x方法通过获取选择器的坐标并将其用作对mouse.move(x +选择器.x,选择器.y)的修改输入。

You can easily write your own move_x method by getting the coordinates of the selector and using these as modified inputs to mouse.move(x + selector.x, selector.y).

有些人仍然相信这样做不行。尝试以下代码段:

Some people still believe this does not work. Try the following snippet:

casper.then(function() {
    this.mouse.down('div.some_selector');
    this.mouse.move(200, 100);
});

casper.then(function() {
    this.mouse.up(200, 100);
});

这篇关于CasperJS:模拟滑动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆