zoukankan      html  css  js  c++  java
  • [译文]casperjs的API-mouse模块

    mouse类

    这个类是对各种鼠标操作的抽象,比如移动,点击,双击,滚动等。它要求一个已经获得DOM属性的casper对象,能用这种方式创造一个鼠标对象:

    var casper = require("casper").create();
    var mouse = require("mouse").create(casper);
    提示:
    一个capser对象已经有一个mouse属性,因此你一般情况下你不需要在脚本里显式声明一个:
    casper.then(function() {
        this.mouse.click(400, 300); // clicks at coordinates x=400; y=300
    });
    click()

    Signature:

    • click(Number x, Number y)
    • click(String selector)

    对匹配的第一个元素执行一次点击,提供一个选择器表达式或者坐标

    casper.then(function() {
        this.mouse.click("#my-link"); // clicks <a id="my-link">hey</a>
        this.mouse.click(400, 300);   // clicks at coordinates x=400; y=300
    });
    提示:
    你可以直接使用Casper#click来替代这个方法
     
    doubleclick()

    Signature:

    • doubleclick(Number x, Number y)
    • doubleclick(String selector)

    对匹配的元素发送一个双击事件

    casper.then(function() {
        this.mouse.doubleclick("#my-link"); // doubleclicks <a id="my-link">hey</a>
        this.mouse.doubleclick(400, 300);   // doubleclicks at coordinates x=400; y=300
    });
    down()

    Signature:

    • down(Number x, Number y)
    • down(String selector)

    对匹配的元素发送一个鼠标按下事件

    casper.then(function() {
        this.mouse.down("#my-link"); // press left button down <a id="my-link">hey</a>
        this.mouse.down(400, 300);   // press left button down at coordinates x=400; y=300
    });
    move()

    Signature:

    • move(Number x, Number y)
    • move(String selector)

    鼠标移动到匹配的元素上

    casper.then(function() {
        this.mouse.move("#my-link"); // moves cursor over <a id="my-link">hey</a>
        this.mouse.move(400, 300);   // moves cursor over coordinates x=400; y=300
    });
    up()

    Signature:

    • up(Number x, Number y)
    • up(String selector)

    对匹配的元素发送一个鼠标放开事件

    casper.then(function() {
        this.mouse.up("#my-link"); // release left button over <a id="my-link">hey</a>
        this.mouse.up(400, 300);   // release left button over coordinates x=400; y=300
    });
  • 相关阅读:
    Linux安装Jenkins
    python实现寻找目录中最新的文件
    python代码实现邮件发送
    面向对象(一) 类与类之间的关系之依赖和关联
    常见模块(五) random模块
    装饰器如何装饰带参数的函数
    常见模块(四) os模块
    常见模块(二) logging模块
    常见模块(三) pickle模块和json模块
    初识模块
  • 原文地址:https://www.cnblogs.com/reach296/p/3942025.html
Copyright © 2011-2022 走看看