Skip to content

selenium.actions

W3C Actions framework: input sources, action items, and the per-session builder.

InputType

enum InputType: string;

W3C input source types.

None

None

A null input source, used only for pauses that align ticks across sources.

Key

Key

A keyboard input source.

Pointer

Pointer

A pointer input source, such as a mouse, pen, or touch device.

Wheel

Wheel

A wheel input source.

Action

struct Action;

A single action item within a tick.

type

string type;

The action kind, such as pause, keyDown, or pointerMove.

value

dchar value;

The key code point for keyDown and keyUp.

button

int button;

The pointer button index for pointerDown, pointerUp, and pointerCancel.

duration

long duration;

The duration in milliseconds for pause, pointerMove, and scroll.

x

long x;

The horizontal coordinate for pointerMove and scroll.

y

long y;

The vertical coordinate for pointerMove and scroll.

deltaX

long deltaX;

The horizontal scroll delta for scroll.

deltaY

long deltaY;

The vertical scroll delta for scroll.

origin

JSONValue origin;

The move origin for pointerMove, as a string or element reference object.

pause

static Action pause(long duration);

A pause action that occupies one tick without changing device state.

keyDown

static Action keyDown(dchar value);

A key press action.

keyUp

static Action keyUp(dchar value);

A key release action.

pointerDown

static Action pointerDown(int button);

A pointer button press action.

pointerUp

static Action pointerUp(int button);

A pointer button release action.

pointerMove

static Action pointerMove(long x, long y, long duration, JSONValue origin);

A pointer move action to x, y relative to origin.

pointerCancel

static Action pointerCancel(int button);

A pointer cancel action that aborts an in-progress pointer interaction.

scroll

static Action scroll(long x, long y, long deltaX, long deltaY, long duration);

A wheel scroll action starting at x, y by deltaX and deltaY.

toJSON

JSONValue toJSON() const;

Serializes the action into the W3C action item object.

Source

struct Source;

A W3C input source and its ordered action items.

type

InputType type;

The input source type.

id

string id;

The opaque id identifying this source within a tick.

pointerType

PointerType pointerType;

The pointer device kind, used only when type is Pointer.

actions

Action[] actions;

The action items, one per tick.

toJSON

JSONValue toJSON() const;

Serializes the source into the W3C action source object.

Actions

class Actions;

Builder for W3C action sequences scoped to one driver session.

Functions append their respective action items to the appropriate input source. Sources are created lazily on first use and keyed by id, so a single builder can coordinate keyboard, pointer, and wheel devices across aligned ticks. The W3C model aligns actions by tick index: the nth action of every source runs concurrently, and shorter sources are padded with implicit pauses. Call perform to dispatch the assembled sequence, or release to cancel every pressed key and button.

this

this(Driver driver);

Constructs an action builder bound to a driver session.

Parameters:

Name Description
Driver driver The session that will execute the assembled actions.

keyDown

Actions keyDown(dchar key, string id = "keyboard");

Presses a key on the keyboard source.

Parameters:

Name Description
dchar key The code point to press, either a printable character or a Key.
string id The keyboard source id, defaulting to keyboard.

keyUp

Actions keyUp(dchar key, string id = "keyboard");

Releases a key on the keyboard source.

Parameters:

Name Description
dchar key The code point to release, either a printable character or a Key.
string id The keyboard source id, defaulting to keyboard.

sendKeys

Actions sendKeys(dstring keys, string id = "keyboard");

Types a string by pressing and releasing each code point in order.

Parameters:

Name Description
dstring keys The string to type, decoded as UTF-8 code points.
string id The keyboard source id, defaulting to keyboard.

pointerDown

Actions pointerDown(int button = Button.Primary, string id = "mouse", PointerType pointerType = PointerType.Mouse);

Presses a pointer button.

Parameters:

Name Description
int button The button index, defaulting to the primary button.
string id The pointer source id, defaulting to mouse.
PointerType pointerType The pointer device kind, defaulting to a mouse.

pointerUp

Actions pointerUp(int button = Button.Primary, string id = "mouse", PointerType pointerType = PointerType.Mouse);

Releases a pointer button.

Parameters:

Name Description
int button The button index, defaulting to the primary button.
string id The pointer source id, defaulting to mouse.
PointerType pointerType The pointer device kind, defaulting to a mouse.

move

Actions move(long x, long y, long duration = 0, string id = "mouse", PointerType pointerType = PointerType.Mouse);

Moves the pointer to viewport coordinates.

Parameters:

Name Description
long x The horizontal offset from the viewport origin.
long y The vertical offset from the viewport origin.
long duration The transition duration in milliseconds.
string id The pointer source id, defaulting to mouse.
PointerType pointerType The pointer device kind, defaulting to a mouse.

move

Actions move(long x, long y, Origin origin, long duration = 0, string id = "mouse", PointerType pointerType = PointerType.Mouse);

Moves the pointer relative to a named origin.

Parameters:

Name Description
long x The horizontal offset from origin.
long y The vertical offset from origin.
Origin origin The reference point, either Viewport or Pointer.
long duration The transition duration in milliseconds.
string id The pointer source id, defaulting to mouse.
PointerType pointerType The pointer device kind, defaulting to a mouse.

move

Actions move(Element element, long x = 0, long y = 0, long duration = 0, string id = "mouse", PointerType pointerType = PointerType.Mouse);

Moves the pointer to the center of an element, plus an optional offset.

Parameters:

Name Description
Element element The element whose center is the move origin.
long x The horizontal offset from the element center.
long y The vertical offset from the element center.
long duration The transition duration in milliseconds.
string id The pointer source id, defaulting to mouse.
PointerType pointerType The pointer device kind, defaulting to a mouse.

click

Actions click(int button = Button.Primary, string id = "mouse", PointerType pointerType = PointerType.Mouse);

Presses and releases a pointer button, producing a single click.

Parameters:

Name Description
int button The button index, defaulting to the primary button.
string id The pointer source id, defaulting to mouse.
PointerType pointerType The pointer device kind, defaulting to a mouse.

doubleClick

Actions doubleClick(int button = Button.Primary, string id = "mouse", PointerType pointerType = PointerType.Mouse);

Presses and releases a pointer button twice, producing a double click.

Parameters:

Name Description
int button The button index, defaulting to the primary button.
string id The pointer source id, defaulting to mouse.
PointerType pointerType The pointer device kind, defaulting to a mouse.

contextClick

Actions contextClick(string id = "mouse", PointerType pointerType = PointerType.Mouse);

Clicks the secondary button, producing a context click.

Parameters:

Name Description
string id The pointer source id, defaulting to mouse.
PointerType pointerType The pointer device kind, defaulting to a mouse.

scroll

Actions scroll(long x, long y, long deltaX, long deltaY, long duration = 0, string id = "wheel");

Scrolls a wheel input source by the given deltas.

Parameters:

Name Description
long x The horizontal coordinate to start scrolling from.
long y The vertical coordinate to start scrolling from.
long deltaX The horizontal scroll distance.
long deltaY The vertical scroll distance.
long duration The scroll duration in milliseconds.
string id The wheel source id, defaulting to wheel.

pause

Actions pause(long duration, string id = "none");

Pauses a single input source for one tick.

Parameters:

Name Description
long duration The pause duration in milliseconds.
string id The source id, defaulting to a none source named none.

perform

Actions perform();

Dispatches the assembled action sequence to the session.

The sequence is sent as a single POST /actions request. The builder remains usable after the call so further actions can be appended and performed again.

release

void release();

Releases every pressed key and pointer button on the session.

Issues DELETE /actions, cancelling any input left in an intermediate state by a previous perform.

actions

Actions actions(Driver driver);

Opens an action builder for a session, used as driver.actions.