fixes #749 - added docs for the mouse module
Showing
1 changed file
with
102 additions
and
0 deletions
docs/modules/mouse.rst
0 → 100644
1 | .. _mouse_module: | ||
2 | |||
3 | ==================== | ||
4 | The ``mouse`` module | ||
5 | ==================== | ||
6 | |||
7 | .. index:: Mouse | ||
8 | |||
9 | The ``Mouse`` class | ||
10 | +++++++++++++++++++ | ||
11 | |||
12 | The ``Mouse`` class is an abstraction on top of various mouse operations like moving, clicking, double-clicking, rollovers, etc. It requires a ``Casper`` instance as a dependency for accessing the DOM. A mouse object can be created that way:: | ||
13 | |||
14 | var casper = require("casper").create(); | ||
15 | var mouse = require("mouse").create(casper); | ||
16 | |||
17 | .. note:: | ||
18 | |||
19 | A ``casper`` instance has a ``mouse`` property already defined, so you usually don't have to create one by hand in your casper scripts:: | ||
20 | |||
21 | casper.then(function() { | ||
22 | this.mouse.click(400, 300); // clicks at coordinates x=400; y=300 | ||
23 | }); | ||
24 | |||
25 | ``click()`` | ||
26 | ------------------------------------------------------------------------------- | ||
27 | |||
28 | **Signature:** | ||
29 | |||
30 | - ``click(Number x, Number y)`` | ||
31 | - ``click(String selector)`` | ||
32 | |||
33 | Performs a click on the first element found matching the provided :doc:`selector expression <../selectors>` or at given coordinates if two numbers are passed:: | ||
34 | |||
35 | casper.then(function() { | ||
36 | this.mouse.click("#my-link"); // clicks <a id="my-link">hey</a> | ||
37 | this.mouse.click(400, 300); // clicks at coordinates x=400; y=300 | ||
38 | }); | ||
39 | |||
40 | .. note:: | ||
41 | |||
42 | You may want to directly use :ref:`Casper#click <casper_click>` instead. | ||
43 | |||
44 | ``doubleclick()`` | ||
45 | ------------------------------------------------------------------------------- | ||
46 | |||
47 | **Signature:** | ||
48 | |||
49 | - ``doubleclick(Number x, Number y)`` | ||
50 | - ``doubleclick(String selector)`` | ||
51 | |||
52 | Sends a ``doubleclick`` mouse event onto the element matching the provided arguments:: | ||
53 | |||
54 | casper.then(function() { | ||
55 | this.mouse.doubleclick("#my-link"); // doubleclicks <a id="my-link">hey</a> | ||
56 | this.mouse.doubleclick(400, 300); // doubleclicks at coordinates x=400; y=300 | ||
57 | }); | ||
58 | |||
59 | ``down()`` | ||
60 | ------------------------------------------------------------------------------- | ||
61 | |||
62 | **Signature:** | ||
63 | |||
64 | - ``down(Number x, Number y)`` | ||
65 | - ``down(String selector)`` | ||
66 | |||
67 | Sends a ``mousedown`` mouse event onto the element matching the provided arguments:: | ||
68 | |||
69 | casper.then(function() { | ||
70 | this.mouse.down("#my-link"); // press left button down <a id="my-link">hey</a> | ||
71 | this.mouse.down(400, 300); // press left button down at coordinates x=400; y=300 | ||
72 | }); | ||
73 | |||
74 | ``move()`` | ||
75 | ------------------------------------------------------------------------------- | ||
76 | |||
77 | **Signature:** | ||
78 | |||
79 | - ``move(Number x, Number y)`` | ||
80 | - ``move(String selector)`` | ||
81 | |||
82 | Moves the mouse cursor onto the element matching the provided arguments:: | ||
83 | |||
84 | casper.then(function() { | ||
85 | this.mouse.move("#my-link"); // moves cursor over <a id="my-link">hey</a> | ||
86 | this.mouse.move(400, 300); // moves cursor over coordinates x=400; y=300 | ||
87 | }); | ||
88 | |||
89 | ``up()`` | ||
90 | ------------------------------------------------------------------------------- | ||
91 | |||
92 | **Signature:** | ||
93 | |||
94 | - ``up(Number x, Number y)`` | ||
95 | - ``up(String selector)`` | ||
96 | |||
97 | Sends a ``mouseup`` mouse event onto the element matching the provided arguments:: | ||
98 | |||
99 | casper.then(function() { | ||
100 | this.mouse.up("#my-link"); // release left button over <a id="my-link">hey</a> | ||
101 | this.mouse.up(400, 300); // release left button over coordinates x=400; y=300 | ||
102 | }); |
-
Please register or sign in to post a comment