Table of Contents

Class Actions

Namespace
OpenQA.Selenium.Interactions
Assembly
WebDriver.dll

Provides a mechanism for building advanced interactions with the browser.

public class Actions : IAction
Inheritance
Actions
Implements
Inherited Members

Constructors

Actions(IWebDriver)

Initializes a new instance of the Actions class.

public Actions(IWebDriver driver)

Parameters

driver IWebDriver

The IWebDriver object on which the actions built will be performed.

Exceptions

ArgumentException

If driver does not implement IActionExecutor.

Actions(IWebDriver, TimeSpan)

Initializes a new instance of the Actions class.

public Actions(IWebDriver driver, TimeSpan duration)

Parameters

driver IWebDriver

The IWebDriver object on which the actions built will be performed.

duration TimeSpan

How long durable action is expected to take.

Exceptions

ArgumentException

If driver does not implement IActionExecutor.

Properties

ActionExecutor

Returns the IActionExecutor for the driver.

protected IActionExecutor ActionExecutor { get; }

Property Value

IActionExecutor

Methods

Build()

Builds the sequence of actions.

public IAction Build()

Returns

IAction

A composite IAction which can be used to perform the actions.

Click()

Clicks the mouse at the last known mouse coordinates.

public Actions Click()

Returns

Actions

A self-reference to this Actions.

Click(IWebElement)

Clicks the mouse on the specified element.

public Actions Click(IWebElement onElement)

Parameters

onElement IWebElement

The element on which to click.

Returns

Actions

A self-reference to this Actions.

ClickAndHold()

Clicks and holds the mouse button at the last known mouse coordinates.

public Actions ClickAndHold()

Returns

Actions

A self-reference to this Actions.

ClickAndHold(IWebElement)

Clicks and holds the mouse button down on the specified element.

public Actions ClickAndHold(IWebElement onElement)

Parameters

onElement IWebElement

The element on which to click and hold.

Returns

Actions

A self-reference to this Actions.

ContextClick()

Right-clicks the mouse at the last known mouse coordinates.

public Actions ContextClick()

Returns

Actions

A self-reference to this Actions.

ContextClick(IWebElement)

Right-clicks the mouse on the specified element.

public Actions ContextClick(IWebElement onElement)

Parameters

onElement IWebElement

The element on which to right-click.

Returns

Actions

A self-reference to this Actions.

DoubleClick()

Double-clicks the mouse at the last known mouse coordinates.

public Actions DoubleClick()

Returns

Actions

A self-reference to this Actions.

DoubleClick(IWebElement)

Double-clicks the mouse on the specified element.

public Actions DoubleClick(IWebElement onElement)

Parameters

onElement IWebElement

The element on which to double-click.

Returns

Actions

A self-reference to this Actions.

DragAndDrop(IWebElement, IWebElement)

Performs a drag-and-drop operation from one element to another.

public Actions DragAndDrop(IWebElement source, IWebElement target)

Parameters

source IWebElement

The element on which the drag operation is started.

target IWebElement

The element on which the drop is performed.

Returns

Actions

A self-reference to this Actions.

DragAndDropToOffset(IWebElement, int, int)

Performs a drag-and-drop operation on one element to a specified offset.

public Actions DragAndDropToOffset(IWebElement source, int offsetX, int offsetY)

Parameters

source IWebElement

The element on which the drag operation is started.

offsetX int

The horizontal offset to which to move the mouse.

offsetY int

The vertical offset to which to move the mouse.

Returns

Actions

A self-reference to this Actions.

GetActiveKeyboard()

Gets the active keyboard device for this Actions class.

public KeyInputDevice GetActiveKeyboard()

Returns

KeyInputDevice

The active keyboard device for this Actions class.

GetActivePointer()

Gets the active pointer device for this Actions class.

public PointerInputDevice GetActivePointer()

Returns

PointerInputDevice

The active pointer device for this Actions class.

GetActiveWheel()

Gets the active wheel device for this Actions class.

public WheelInputDevice GetActiveWheel()

Returns

WheelInputDevice

The active wheel device for this Actions class.

GetLocatableFromElement(IWebElement)

Gets the ILocatable instance of the specified IWebElement.

protected static ILocatable GetLocatableFromElement(IWebElement element)

Parameters

element IWebElement

The IWebElement to get the location of.

Returns

ILocatable

The ILocatable of the IWebElement.

KeyDown(IWebElement, string)

Sends a modifier key down message to the specified element in the browser.

public Actions KeyDown(IWebElement element, string theKey)

Parameters

element IWebElement

The element to which to send the key command.

theKey string

The key to be sent.

Returns

Actions

A self-reference to this Actions.

Exceptions

ArgumentException

If the key sent is not is not one of Shift, Control, Alt, Meta, Command,LeftAlt, LeftControl,LeftShift.

KeyDown(string)

Sends a modifier key down message to the browser.

public Actions KeyDown(string theKey)

Parameters

theKey string

The key to be sent.

Returns

Actions

A self-reference to this Actions.

Exceptions

ArgumentException

If the key sent is not is not one of Shift, Control, Alt, Meta, Command,LeftAlt, LeftControl,LeftShift.

KeyUp(IWebElement, string)

Sends a modifier up down message to the specified element in the browser.

public Actions KeyUp(IWebElement element, string theKey)

Parameters

element IWebElement

The element to which to send the key command.

theKey string

The key to be sent.

Returns

Actions

A self-reference to this Actions.

Exceptions

ArgumentException

If the key sent is not is not one of Shift, Control, Alt, Meta, Command,LeftAlt, LeftControl,LeftShift.

KeyUp(string)

Sends a modifier key up message to the browser.

public Actions KeyUp(string theKey)

Parameters

theKey string

The key to be sent.

Returns

Actions

A self-reference to this Actions.

Exceptions

ArgumentException

If the key sent is not is not one of Shift, Control, Alt, Meta, Command,LeftAlt, LeftControl,LeftShift.

MoveByOffset(int, int)

Moves the mouse to the specified offset of the last known mouse coordinates.

public Actions MoveByOffset(int offsetX, int offsetY)

Parameters

offsetX int

The horizontal offset to which to move the mouse.

offsetY int

The vertical offset to which to move the mouse.

Returns

Actions

A self-reference to this Actions.

MoveToElement(IWebElement)

Moves the mouse to the specified element.

public Actions MoveToElement(IWebElement toElement)

Parameters

toElement IWebElement

The element to which to move the mouse.

Returns

Actions

A self-reference to this Actions.

MoveToElement(IWebElement, int, int)

Moves the mouse to the specified offset of the top-left corner of the specified element. In Selenium 4.3 the origin for the offset will be the in-view center point of the element.

public Actions MoveToElement(IWebElement toElement, int offsetX, int offsetY)

Parameters

toElement IWebElement

The element to which to move the mouse.

offsetX int

The horizontal offset to which to move the mouse.

offsetY int

The vertical offset to which to move the mouse.

Returns

Actions

A self-reference to this Actions.

MoveToLocation(int, int)

Moves the mouse from the upper left corner of the current viewport by the provided offset.

public Actions MoveToLocation(int offsetX, int offsetY)

Parameters

offsetX int

The horizontal offset to which to move the mouse.

offsetY int

The vertical offset to which to move the mouse.

Returns

Actions

A self-reference to this Actions.

Pause(TimeSpan)

Performs a Pause.

public Actions Pause(TimeSpan duration)

Parameters

duration TimeSpan

How long to pause the action chain.

Returns

Actions

A self-reference to this Actions.

Perform()

Performs the currently built action.

public void Perform()

Release()

Releases the mouse button at the last known mouse coordinates.

public Actions Release()

Returns

Actions

A self-reference to this Actions.

Release(IWebElement)

Releases the mouse button on the specified element.

public Actions Release(IWebElement onElement)

Parameters

onElement IWebElement

The element on which to release the button.

Returns

Actions

A self-reference to this Actions.

Reset()

Clears the list of actions to be performed.

public void Reset()

ScrollByAmount(int, int)

Scrolls by provided amounts with the origin in the top left corner of the viewport.

public Actions ScrollByAmount(int deltaX, int deltaY)

Parameters

deltaX int

Distance along X axis to scroll using the wheel. A negative value scrolls left.

deltaY int

Distance along Y axis to scroll using the wheel. A negative value scrolls up.

Returns

Actions

A self-reference to this Actions.

ScrollFromOrigin(ScrollOrigin, int, int)

Scrolls by provided amount based on a provided origin.

public Actions ScrollFromOrigin(WheelInputDevice.ScrollOrigin scrollOrigin, int deltaX, int deltaY)

Parameters

scrollOrigin WheelInputDevice.ScrollOrigin

Where scroll originates (viewport or element center) plus provided offsets.

deltaX int

Distance along X axis to scroll using the wheel. A negative value scrolls left.

deltaY int

Distance along Y axis to scroll using the wheel. A negative value scrolls up.

Returns

Actions

A self-reference to this Actions.

Remarks

The scroll origin is either the center of an element or the upper left of the viewport plus any offsets. If the origin is an element, and the element is not in the viewport, the bottom of the element will first be scrolled to the bottom of the viewport.

Exceptions

MoveTargetOutOfBoundsException

If the origin with offset is outside the viewport.

ScrollToElement(IWebElement)

If the element is outside the viewport, scrolls the bottom of the element to the bottom of the viewport.

public Actions ScrollToElement(IWebElement element)

Parameters

element IWebElement

Which element to scroll into the viewport.

Returns

Actions

A self-reference to this Actions.

SendKeys(IWebElement, string)

Sends a sequence of keystrokes to the specified element in the browser.

public Actions SendKeys(IWebElement element, string keysToSend)

Parameters

element IWebElement

The element to which to send the keystrokes.

keysToSend string

The keystrokes to send to the browser.

Returns

Actions

A self-reference to this Actions.

SendKeys(string)

Sends a sequence of keystrokes to the browser.

public Actions SendKeys(string keysToSend)

Parameters

keysToSend string

The keystrokes to send to the browser.

Returns

Actions

A self-reference to this Actions.

SetActiveKeyboard(string)

Sets the active keyboard device for this Actions class.

public Actions SetActiveKeyboard(string name)

Parameters

name string

The name of the keyboard device to set as active.

Returns

Actions

A self-reference to this Actions class.

Exceptions

InvalidOperationException

If a device with this name exists but is not a keyboard.

SetActivePointer(PointerKind, string)

Sets the active pointer device for this Actions class.

public Actions SetActivePointer(PointerKind kind, string name)

Parameters

kind PointerKind

The kind of pointer device to set as active.

name string

The name of the pointer device to set as active.

Returns

Actions

A self-reference to this Actions class.

Exceptions

InvalidOperationException

If a device with this name exists but is not a pointer.

SetActiveWheel(string)

Sets the active wheel device for this Actions class.

public Actions SetActiveWheel(string name)

Parameters

name string

The name of the wheel device to set as active.

Returns

Actions

A self-reference to this Actions class.

Exceptions

InvalidOperationException

If a device with this name exists but is not a wheel.