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
driverIWebDriverThe IWebDriver object on which the actions built will be performed.
Exceptions
- ArgumentException
If
driverdoes not implement IActionExecutor.
Actions(IWebDriver, TimeSpan)
Initializes a new instance of the Actions class.
public Actions(IWebDriver driver, TimeSpan duration)
Parameters
driverIWebDriverThe IWebDriver object on which the actions built will be performed.
durationTimeSpanHow long durable action is expected to take.
Exceptions
- ArgumentException
If
driverdoes 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
onElementIWebElementThe element on which to click.
Returns
Exceptions
- ArgumentNullException
If
onElementis null.
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
onElementIWebElementThe element on which to click and hold.
Returns
Exceptions
- ArgumentNullException
If
onElementis null.
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
onElementIWebElementThe element on which to right-click.
Returns
Exceptions
- ArgumentNullException
If
onElementis null.
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
onElementIWebElementThe element on which to double-click.
Returns
Exceptions
- ArgumentNullException
If
onElementis null.
DragAndDrop(IWebElement, IWebElement)
Performs a drag-and-drop operation from one element to another.
public Actions DragAndDrop(IWebElement source, IWebElement target)
Parameters
sourceIWebElementThe element on which the drag operation is started.
targetIWebElementThe element on which the drop is performed.
Returns
Exceptions
- ArgumentNullException
If
sourceortargetare null.
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
sourceIWebElementThe element on which the drag operation is started.
offsetXintThe horizontal offset to which to move the mouse.
offsetYintThe vertical offset to which to move the mouse.
Returns
Exceptions
- ArgumentNullException
If
sourceis null.
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
elementIWebElementThe 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
elementIWebElementThe element to which to send the key command.
theKeystringThe 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
theKeystringThe 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
elementIWebElementThe element to which to send the key command.
theKeystringThe 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
theKeystringThe 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
offsetXintThe horizontal offset to which to move the mouse.
offsetYintThe vertical offset to which to move the mouse.
Returns
MoveToElement(IWebElement)
Moves the mouse to the specified element.
public Actions MoveToElement(IWebElement toElement)
Parameters
toElementIWebElementThe element to which to move the mouse.
Returns
Exceptions
- ArgumentNullException
If
toElementis null.
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
toElementIWebElementThe element to which to move the mouse.
offsetXintThe horizontal offset to which to move the mouse.
offsetYintThe 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
offsetXintThe horizontal offset to which to move the mouse.
offsetYintThe vertical offset to which to move the mouse.
Returns
Pause(TimeSpan)
Performs a Pause.
public Actions Pause(TimeSpan duration)
Parameters
durationTimeSpanHow long to pause the action chain.
Returns
Exceptions
- ArgumentException
If
durationis negative.
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
onElementIWebElementThe element on which to release the button.
Returns
Exceptions
- ArgumentNullException
If
onElementis null.
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
deltaXintDistance along X axis to scroll using the wheel. A negative value scrolls left.
deltaYintDistance 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
scrollOriginWheelInputDevice.ScrollOriginWhere scroll originates (viewport or element center) plus provided offsets.
deltaXintDistance along X axis to scroll using the wheel. A negative value scrolls left.
deltaYintDistance 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.
- ArgumentNullException
If
scrollOriginis null.- ArgumentException
If both or either of Viewport and Element are set.
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
elementIWebElementWhich element to scroll into the viewport.
Returns
Exceptions
- ArgumentNullException
If
elementis null.
SendKeys(IWebElement?, string)
Sends a sequence of keystrokes to the specified element in the browser.
public Actions SendKeys(IWebElement? element, string keysToSend)
Parameters
elementIWebElementThe element to which to send the keystrokes.
keysToSendstringThe keystrokes to send to the browser.
Returns
Exceptions
SendKeys(string)
Sends a sequence of keystrokes to the browser.
public Actions SendKeys(string keysToSend)
Parameters
keysToSendstringThe keystrokes to send to the browser.
Returns
Exceptions
SetActiveKeyboard(string)
Sets the active keyboard device for this Actions class.
public Actions SetActiveKeyboard(string name)
Parameters
namestringThe 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
kindPointerKindThe kind of pointer device to set as active.
namestringThe 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
namestringThe 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.