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
IWebDriverThe 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
IWebDriverThe IWebDriver object on which the actions built will be performed.
duration
TimeSpanHow 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
Methods
Build()
Builds the sequence of actions.
public IAction Build()
Returns
Click()
Clicks the mouse at the last known mouse coordinates.
public Actions Click()
Returns
Click(IWebElement)
Clicks the mouse on the specified element.
public Actions Click(IWebElement onElement)
Parameters
onElement
IWebElementThe element on which to click.
Returns
ClickAndHold()
Clicks and holds the mouse button at the last known mouse coordinates.
public Actions ClickAndHold()
Returns
ClickAndHold(IWebElement)
Clicks and holds the mouse button down on the specified element.
public Actions ClickAndHold(IWebElement onElement)
Parameters
onElement
IWebElementThe element on which to click and hold.
Returns
ContextClick()
Right-clicks the mouse at the last known mouse coordinates.
public Actions ContextClick()
Returns
ContextClick(IWebElement)
Right-clicks the mouse on the specified element.
public Actions ContextClick(IWebElement onElement)
Parameters
onElement
IWebElementThe element on which to right-click.
Returns
DoubleClick()
Double-clicks the mouse at the last known mouse coordinates.
public Actions DoubleClick()
Returns
DoubleClick(IWebElement)
Double-clicks the mouse on the specified element.
public Actions DoubleClick(IWebElement onElement)
Parameters
onElement
IWebElementThe element on which to double-click.
Returns
DragAndDrop(IWebElement, IWebElement)
Performs a drag-and-drop operation from one element to another.
public Actions DragAndDrop(IWebElement source, IWebElement target)
Parameters
source
IWebElementThe element on which the drag operation is started.
target
IWebElementThe element on which the drop is performed.
Returns
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
IWebElementThe element on which the drag operation is started.
offsetX
intThe horizontal offset to which to move the mouse.
offsetY
intThe vertical offset to which to move the mouse.
Returns
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
IWebElementThe 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
IWebElementThe element to which to send the key command.
theKey
stringThe key to be sent.
Returns
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
stringThe key to be sent.
Returns
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
IWebElementThe element to which to send the key command.
theKey
stringThe key to be sent.
Returns
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
stringThe key to be sent.
Returns
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
intThe horizontal offset to which to move the mouse.
offsetY
intThe vertical offset to which to move the mouse.
Returns
MoveToElement(IWebElement)
Moves the mouse to the specified element.
public Actions MoveToElement(IWebElement toElement)
Parameters
toElement
IWebElementThe element to which to move the mouse.
Returns
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
IWebElementThe element to which to move the mouse.
offsetX
intThe horizontal offset to which to move the mouse.
offsetY
intThe vertical offset to which to move the mouse.
Returns
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
intThe horizontal offset to which to move the mouse.
offsetY
intThe vertical offset to which to move the mouse.
Returns
Pause(TimeSpan)
Performs a Pause.
public Actions Pause(TimeSpan duration)
Parameters
duration
TimeSpanHow long to pause the action chain.
Returns
Perform()
Performs the currently built action.
public void Perform()
Release()
Releases the mouse button at the last known mouse coordinates.
public Actions Release()
Returns
Release(IWebElement)
Releases the mouse button on the specified element.
public Actions Release(IWebElement onElement)
Parameters
onElement
IWebElementThe element on which to release the button.
Returns
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
intDistance along X axis to scroll using the wheel. A negative value scrolls left.
deltaY
intDistance along Y axis to scroll using the wheel. A negative value scrolls up.
Returns
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.ScrollOriginWhere scroll originates (viewport or element center) plus provided offsets.
deltaX
intDistance along X axis to scroll using the wheel. A negative value scrolls left.
deltaY
intDistance along Y axis to scroll using the wheel. A negative value scrolls up.
Returns
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
IWebElementWhich element to scroll into the viewport.
Returns
SendKeys(IWebElement, string)
Sends a sequence of keystrokes to the specified element in the browser.
public Actions SendKeys(IWebElement element, string keysToSend)
Parameters
element
IWebElementThe element to which to send the keystrokes.
keysToSend
stringThe keystrokes to send to the browser.
Returns
SendKeys(string)
Sends a sequence of keystrokes to the browser.
public Actions SendKeys(string keysToSend)
Parameters
keysToSend
stringThe keystrokes to send to the browser.
Returns
SetActiveKeyboard(string)
Sets the active keyboard device for this Actions class.
public Actions SetActiveKeyboard(string name)
Parameters
name
stringThe 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
PointerKindThe kind of pointer device to set as active.
name
stringThe 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
stringThe 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.