Constructor
new Actions(executornon-null, options)
Name | Type | Description |
---|---|---|
executor | Executor | The object to execute the configured actions with. |
options | Object | Options for this action sequence (see class description for details). |
- Source
Methods
clear() → (non-null) {Promise.<void>}
Releases all keys, pointers, and clears internal state.
- Source
a promise that will resolve when finished clearing all action state.
- Type:
- Promise.<void>
click(element) → (non-null) {Actions}
Short-hand for performing a simple left-click (down/up) with the mouse.
Name | Type | Description |
---|---|---|
element |
- Source
a self reference.
- Type:
- Actions
contextClick(element) → (non-null) {Actions}
Short-hand for performing a simple right-click (down/up) with the mouse.
Name | Type | Description |
---|---|---|
element |
- Source
a self reference.
- Type:
- Actions
doubleClick(element) → (non-null) {Actions}
Short-hand for performing a double left-click with the mouse.
Name | Type | Description |
---|---|---|
element |
- Source
a self reference.
- Type:
- Actions
dragAndDrop(from, to) → (non-null) {Actions}
Configures a drag-and-drop action consisting of the following steps:
- Move to the center of the
from
element (element to be dragged). - Press the left mouse button.
- If the
to
target is a WebElement, move the mouse to its center. Otherwise, move the mouse by the specified offset. - Release the left mouse button.
Name | Type | Description |
---|---|---|
from | ||
to |
- Source
a self reference.
- Type:
- Actions
insert(devicenon-null, …actionsnon-null) → (non-null) {Actions}
Appends actions
to the end of the current sequence for the given device
. If device synchronization is enabled, after inserting the actions, pauses will be inserted for all other devices to ensure all action sequences are the same length.
Name | Type | Attributes | Description |
---|---|---|---|
device | Device | the device to update. | |
actions | Action | <repeatable> | the actions to insert. |
- Source
a self reference.
- Type:
- Actions
keyDown(key) → (non-null) {Actions}
Inserts an action to press a single key.
Name | Type | Description |
---|---|---|
key | Key | | the key to press. This key may be specified as a Key value, a specific unicode code point, or a string containing a single unicode code point. |
- Source
a self reference.
- Type:
- Actions
keyUp(key) → (non-null) {Actions}
Inserts an action to release a single key.
Name | Type | Description |
---|---|---|
key | Key | | the key to release. This key may be specified as a Key value, a specific unicode code point, or a string containing a single unicode code point. |
- Source
a self reference.
- Type:
- Actions
keyboard() → (non-null) {Keyboard}
- Source
the keyboard device handle.
- Type:
- Keyboard
mouse() → (non-null) {Pointer}
- Source
the mouse pointer device handle.
- Type:
- Pointer
move() → (non-null) {Actions}
Inserts an action for moving the mouse x
and y
pixels relative to the specified origin
. The origin
may be defined as the mouse's current position, the top-left corner of the viewport, or the center of a specific WebElement. Default is top left corner of the view-port if origin is not specified
You may adjust how long the remote end should take, in milliseconds, to perform the move using the duration
parameter (defaults to 100 ms). The number of incremental move events generated over this duration is an implementation detail for the remote end.
Type | Description |
---|---|
- Source
a self reference.
- Type:
- Actions
pause(durationopt, …devicesnon-null) → (non-null) {Actions}
Inserts a pause action for the specified devices, ensuring each device is idle for a tick. The length of the pause (in milliseconds) may be specified as the first parameter to this method (defaults to 0). Otherwise, you may just specify the individual devices that should pause.
If no devices are specified, a pause action will be created (using the same duration) for every device.
When device synchronization is enabled (the default for new Actions objects), there is no need to specify devices as pausing one automatically pauses the others for the same duration. In other words, the following are all equivalent:
let a1 = driver.actions();
a1.pause(100).perform();
let a2 = driver.actions();
a2.pause(100, a2.keyboard()).perform();
// Synchronization ensures a2.mouse() is automatically paused too.
let a3 = driver.actions();
a3.pause(100, a3.keyboard(), a3.mouse()).perform();
When device synchronization is disabled, you can cause individual devices to pause during a tick. For example, to hold the SHIFT key down while moving the mouse:
let actions = driver.actions({async: true});
actions.keyDown(Key.SHIFT);
actions.pause(actions.mouse()) // Pause for shift down
.press(Button.LEFT)
.move({x: 10, y: 10})
.release(Button.LEFT);
actions
.pause(
actions.keyboard(), // Pause for press left
actions.keyboard(), // Pause for move
actions.keyboard()) // Pause for release left
.keyUp(Key.SHIFT);
await actions.perform();
Name | Type | Attributes | Description |
---|---|---|---|
duration | number | | <optional> | The length of the pause to insert, in milliseconds. Alternatively, the duration may be omitted (yielding a default 0 ms pause), and the first device to pause may be specified. |
devices | Device | <repeatable> | The devices to insert the pause for. If no devices are specified, the pause will be inserted for all devices. |
- Source
a self reference.
- Type:
- Actions
(async) perform() → (non-null) {Promise.<void>}
Performs the configured action sequence.
- Source
a promise that will resolve when all actions have been completed.
- Type:
- Promise.<void>
press(buttonopt, non-null) → (non-null) {Actions}
Inserts an action to press a mouse button at the mouse's current location.
Name | Type | Attributes | Description |
---|---|---|---|
button | Button | <optional> | The button to press; defaults to |
- Source
a self reference.
- Type:
- Actions
release(buttonopt, non-null) → (non-null) {Actions}
Inserts an action to release a mouse button at the mouse's current location.
Name | Type | Attributes | Description |
---|---|---|---|
button | Button | <optional> | The button to release; defaults to |
- Source
a self reference.
- Type:
- Actions
scroll(x, y, deltax, deltay, duration) → (non-null) {Actions}
scrolls a page via the coordinates given
Name | Type | Description |
---|---|---|
x | number | starting x coordinate |
y | number | starting y coordinate |
deltax | number | delta x to scroll to target |
deltay | number | delta y to scroll to target |
duration | number | duration ratio be the ratio of time delta and duration |
- Source
An action to scroll with this device.
- Type:
- Actions
sendKeys(…keys) → (non-null) {Actions}
Inserts a sequence of actions to type the provided key sequence. For each key, this will record a pair of keyDown and keyUp actions. An implication of this pairing is that modifier keys (e.g. Key.SHIFT) will always be immediately released. In other words, sendKeys(Key.SHIFT, 'a')
is the same as typing sendKeys('a')
, not sendKeys('A')
.
Name | Type | Attributes | Description |
---|---|---|---|
keys | Key | | <repeatable> | the keys to type. |
- Source
a self reference.
- Type:
- Actions
synchronize(…devicesnon-null) → (non-null) {Actions}
Ensures the action sequence for every device referenced in this action sequence is the same length. For devices whose sequence is too short, this will insert pauses so that every device has an explicit action defined at each tick.
Name | Type | Attributes | Description |
---|---|---|---|
devices | Device | <repeatable> | The specific devices to synchronize. If unspecified, the action sequences for every device will be synchronized. |
- Source
a self reference.
- Type:
- Actions
wheel() → (non-null) {Wheel}
- Source
the wheel device handle.
- Type:
- Wheel