【问题标题】:CasperJS: Simulate swipe-eventCasperJS:模拟滑动事件
【发布时间】:2014-09-15 08:50:21
【问题描述】:

我尝试构建一些 casperjs 测试。到目前为止一切顺利,但有一件事我失败了:

为滑动事件构建测试。

我需要这样的东西:

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 这样的函数。

有人有想法吗?

【问题讨论】:

  • 它是如何失败的?你有我们可以试用的示例页面吗?
  • 感谢您的回答。我更新了我的问题。是的,功能“move_x”是我正在寻找的。或者另一种方法来做到这一点
  • 你找到答案了吗?即使您不这样做,也请提供否定答案。
  • 其实:我不可能。

标签: javascript casperjs


【解决方案1】:

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

有些人仍然认为这不起作用。试试下面的 sn-p:

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

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

【讨论】:

  • 我也有同样的答案。它被否决了,我在 19 小时前删除了它。根据 OP,它不起作用:“感谢您的建议。但它不起作用。我发现 PhantomJS 在移动鼠标时不按住任何按钮(请参阅:github.com/n1k0/casperjs/issues/147)。: -("
  • 你能提供一个完整的脚本作为粘贴/要点吗?我还没有找到好的滑动示例页面。
猜你喜欢
  • 2022-11-08
  • 2011-11-13
  • 1970-01-01
  • 2010-09-27
  • 1970-01-01
  • 1970-01-01
  • 2020-09-20
  • 2015-09-01
  • 2020-02-29
相关资源
最近更新 更多