public class Actions
extends java.lang.Object
Implements the builder pattern: Builds a CompositeAction containing all actions specified by the method calls.
Modifier and Type | Class and Description |
---|---|
private static class |
Actions.BuiltAction |
Modifier and Type | Field and Description |
---|---|
protected CompositeAction |
action |
private java.lang.RuntimeException |
actionsException |
private KeyInput |
defaultKeyboard |
private PointerInput |
defaultMouse |
private org.openqa.selenium.WebDriver |
driver |
private org.openqa.selenium.interactions.Keyboard |
jsonKeyboard |
private org.openqa.selenium.interactions.Mouse |
jsonMouse |
private static java.util.logging.Logger |
LOG |
private java.util.Map<org.openqa.selenium.interactions.InputSource,org.openqa.selenium.interactions.Sequence> |
sequences |
Constructor and Description |
---|
Actions(org.openqa.selenium.interactions.Keyboard keyboard)
Deprecated.
Use the new interactions API.
|
Actions(org.openqa.selenium.interactions.Keyboard keyboard,
org.openqa.selenium.interactions.Mouse mouse)
Deprecated.
Use the new interactions APIs.
|
Actions(org.openqa.selenium.WebDriver driver) |
Modifier and Type | Method and Description |
---|---|
private Actions |
addKeyAction(java.lang.CharSequence key,
java.util.function.IntConsumer consumer) |
private org.openqa.selenium.Keys |
asKeys(java.lang.CharSequence key) |
org.openqa.selenium.interactions.Action |
build()
Generates a composite action containing all actions so far, ready to be performed (and
resets the internal builder state, so subsequent calls to
build() will contain fresh
sequences). |
Actions |
click()
Clicks at the current mouse location.
|
Actions |
click(org.openqa.selenium.WebElement target)
Clicks in the middle of the given element.
|
Actions |
clickAndHold()
Clicks (without releasing) at the current mouse location.
|
Actions |
clickAndHold(org.openqa.selenium.WebElement target)
Clicks (without releasing) in the middle of the given element.
|
private Actions |
clickInTicks(PointerInput.MouseButton button) |
Actions |
contextClick()
Performs a context-click at the current mouse location.
|
Actions |
contextClick(org.openqa.selenium.WebElement target)
Performs a context-click at middle of the given element.
|
Actions |
doubleClick()
Performs a double-click at the current mouse location.
|
Actions |
doubleClick(org.openqa.selenium.WebElement target)
Performs a double-click at middle of the given element.
|
Actions |
dragAndDrop(org.openqa.selenium.WebElement source,
org.openqa.selenium.WebElement target)
A convenience method that performs click-and-hold at the location of the source element,
moves to the location of the target element, then releases the mouse.
|
Actions |
dragAndDropBy(org.openqa.selenium.WebElement source,
int xOffset,
int yOffset)
A convenience method that performs click-and-hold at the location of the source element,
moves by a given offset, then releases the mouse.
|
private Actions |
focusInTicks(org.openqa.selenium.WebElement target) |
private org.openqa.selenium.interactions.Sequence |
getSequence(org.openqa.selenium.interactions.InputSource source) |
private boolean |
isBuildingActions() |
Actions |
keyDown(java.lang.CharSequence key)
Performs a modifier key press.
|
Actions |
keyDown(org.openqa.selenium.WebElement target,
java.lang.CharSequence key)
Performs a modifier key press after focusing on an element.
|
Actions |
keyUp(java.lang.CharSequence key)
Performs a modifier key release.
|
Actions |
keyUp(org.openqa.selenium.WebElement target,
java.lang.CharSequence key)
Performs a modifier key release after focusing on an element.
|
Actions |
moveByOffset(int xOffset,
int yOffset)
Moves the mouse from its current position (or 0,0) by the given offset.
|
private Actions |
moveInTicks(org.openqa.selenium.WebElement target,
int xOffset,
int yOffset) |
Actions |
moveToElement(org.openqa.selenium.WebElement target)
Moves the mouse to the middle of the element.
|
Actions |
moveToElement(org.openqa.selenium.WebElement target,
int xOffset,
int yOffset)
Moves the mouse to an offset from the top-left corner of the element.
|
Actions |
pause(java.time.Duration duration) |
Actions |
pause(long pause)
Deprecated.
|
void |
perform()
A convenience method for performing the actions without calling build() first.
|
Actions |
release()
Releases the depressed left mouse button at the current mouse location.
|
Actions |
release(org.openqa.selenium.WebElement target)
Releases the depressed left mouse button, in the middle of the given element.
|
Actions |
sendKeys(java.lang.CharSequence... keys)
Sends keys to the active element.
|
Actions |
sendKeys(org.openqa.selenium.WebElement target,
java.lang.CharSequence... keys)
Equivalent to calling:
Actions.click(element).sendKeys(keysToSend).
This method is different from
WebElement.sendKeys(CharSequence...) - see
sendKeys(CharSequence...) for details how. |
private Actions |
sendKeysInTicks(java.lang.CharSequence... keys) |
Actions |
tick(org.openqa.selenium.interactions.Action action) |
Actions |
tick(org.openqa.selenium.interactions.Interaction... actions) |
private static final java.util.logging.Logger LOG
private final org.openqa.selenium.WebDriver driver
private final java.util.Map<org.openqa.selenium.interactions.InputSource,org.openqa.selenium.interactions.Sequence> sequences
private final PointerInput defaultMouse
private final KeyInput defaultKeyboard
private final org.openqa.selenium.interactions.Keyboard jsonKeyboard
private final org.openqa.selenium.interactions.Mouse jsonMouse
protected CompositeAction action
private java.lang.RuntimeException actionsException
public Actions(org.openqa.selenium.WebDriver driver)
@Deprecated public Actions(org.openqa.selenium.interactions.Keyboard keyboard, org.openqa.selenium.interactions.Mouse mouse)
keyboard
- the Keyboard
implementation to delegate to.mouse
- the Mouse
implementation to delegate to.@Deprecated public Actions(org.openqa.selenium.interactions.Keyboard keyboard)
keyboard
- implementation to delegate to.public Actions keyDown(java.lang.CharSequence key)
key
- Either Keys.SHIFT
, Keys.ALT
or Keys.CONTROL
. If the
provided key is none of those, IllegalArgumentException
is thrown.public Actions keyDown(org.openqa.selenium.WebElement target, java.lang.CharSequence key)
key
- Either Keys.SHIFT
, Keys.ALT
or Keys.CONTROL
. If the
provided key is none of those, IllegalArgumentException
is thrown.target
- WebElement to perform the actionkeyDown(CharSequence)
public Actions keyUp(java.lang.CharSequence key)
key
- Either Keys.SHIFT
, Keys.ALT
or Keys.CONTROL
.public Actions keyUp(org.openqa.selenium.WebElement target, java.lang.CharSequence key)
key
- Either Keys.SHIFT
, Keys.ALT
or Keys.CONTROL
.target
- WebElement to perform the action onon behaviour regarding non-depressed modifier keys.
public Actions sendKeys(java.lang.CharSequence... keys)
WebElement.sendKeys(CharSequence...)
on the active element in two ways:
keys
- The keys.WebElement.sendKeys(CharSequence...)
public Actions sendKeys(org.openqa.selenium.WebElement target, java.lang.CharSequence... keys)
WebElement.sendKeys(CharSequence...)
- see
sendKeys(CharSequence...)
for details how.target
- element to focus on.keys
- The keys.sendKeys(java.lang.CharSequence[])
private org.openqa.selenium.Keys asKeys(java.lang.CharSequence key)
private Actions sendKeysInTicks(java.lang.CharSequence... keys)
private Actions addKeyAction(java.lang.CharSequence key, java.util.function.IntConsumer consumer)
public Actions clickAndHold(org.openqa.selenium.WebElement target)
target
- Element to move to and click.public Actions clickAndHold()
public Actions release(org.openqa.selenium.WebElement target)
clickAndHold()
first will result in
undefined behaviour.target
- Element to release the mouse button above.public Actions release()
release(org.openqa.selenium.WebElement)
public Actions click(org.openqa.selenium.WebElement target)
target
- Element to click.public Actions click()
moveToElement(org.openqa.selenium.WebElement, int, int)
or
moveByOffset(int, int)
.private Actions clickInTicks(PointerInput.MouseButton button)
private Actions focusInTicks(org.openqa.selenium.WebElement target)
public Actions doubleClick(org.openqa.selenium.WebElement target)
target
- Element to move to.public Actions doubleClick()
public Actions moveToElement(org.openqa.selenium.WebElement target)
target
- element to move to.public Actions moveToElement(org.openqa.selenium.WebElement target, int xOffset, int yOffset)
target
- element to move to.xOffset
- Offset from the top-left corner. A negative value means coordinates left from
the element.yOffset
- Offset from the top-left corner. A negative value means coordinates above
the element.private Actions moveInTicks(org.openqa.selenium.WebElement target, int xOffset, int yOffset)
public Actions moveByOffset(int xOffset, int yOffset)
xOffset
- horizontal offset. A negative value means moving the mouse left.yOffset
- vertical offset. A negative value means moving the mouse up.MoveTargetOutOfBoundsException
- if the provided offset is outside the document's
boundaries.public Actions contextClick(org.openqa.selenium.WebElement target)
target
- Element to move to.public Actions contextClick()
public Actions dragAndDrop(org.openqa.selenium.WebElement source, org.openqa.selenium.WebElement target)
source
- element to emulate button down at.target
- element to move to and release the mouse at.public Actions dragAndDropBy(org.openqa.selenium.WebElement source, int xOffset, int yOffset)
source
- element to emulate button down at.xOffset
- horizontal move offset.yOffset
- vertical move offset.@Deprecated public Actions pause(long pause)
pause
- pause duration, in milliseconds.public Actions pause(java.time.Duration duration)
public Actions tick(org.openqa.selenium.interactions.Interaction... actions)
public Actions tick(org.openqa.selenium.interactions.Action action)
public org.openqa.selenium.interactions.Action build()
build()
will contain fresh
sequences).public void perform()
private org.openqa.selenium.interactions.Sequence getSequence(org.openqa.selenium.interactions.InputSource source)
private boolean isBuildingActions()