Class Action
id, type, and subtype
represents a single low-level WebDriver action as defined by the
W3C WebDriver Actions specification.
This class stores the raw action parameters (such as duration, key value, button, pointer type,
and target element) required to later synthesize an HtmlUnit-specific HtmlUnitInputProcessor.HtmlUnitAction.
The type field corresponds to a WebDriver input source type (e.g. "pointer",
"key", "none"). The subtype indicates the specific action to execute
for that input source (e.g. "pointerMove", "pointerDown", "keyUp").
For example:
- A pointer action with
subtype="pointerDown"requires a pointer button. - A key action with
subtype="keyDown"requires a key value. - Pause actions (
subtype="pause") contain only duration.
After the action object is configured, buildHtmlUnitAction() converts it to an
HtmlUnit-specific input action that can be processed by HtmlUnitInputProcessor.
- Author:
- Ronald Brill
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionConverts this WebDriver action object into an HtmlUnit-specific input action.Returns the pointer button associated with apointerDownorpointerUpaction.Returns the DOM element associated with this action, if any.Returns the duration associated with this action.Returns the pointer type for this action.getValue()Returns the key value associated with this action.voidsetButton(int button) Sets the pointer button forpointerDownorpointerUp.voidsetDomElement(DomElement domElement) Sets the DOM element associated with this action.voidsetDuration(int duration) Sets the duration associated with this action.voidsetPointerType(String pointerType) Sets the pointer type for this action.voidSets the key value for a keyboard action.toString()Returns a human-readable string describing this action, including all parameters that have been set.
-
Constructor Details
-
Action
Creates a new WebDriver action object.- Parameters:
id- A unique identifier for the input source that this action belongs to. For example, the ID for a pointer device, keyboard, or virtual device.type- The WebDriver action source type. Common values include:"pointer"— mouse/touch/pen actions"key"— keyboard actions"none"— virtual device used only for pause actions
subtype- The specific action subtype. Examples include:"pointerMove","pointerDown","pointerUp","pause""keyDown","keyUp","pause"
-
-
Method Details
-
getDuration
Returns the duration associated with this action.Duration is used for pause actions or timed movements (e.g.
pointerMove).- Returns:
- duration in milliseconds, or
nullif no duration is defined
-
setDuration
public void setDuration(int duration) Sets the duration associated with this action.- Parameters:
duration- Duration in milliseconds. Must be non-negative according to the W3C spec.
-
getValue
Returns the key value associated with this action.This applies only to keyboard actions such as
keyDownorkeyUp. Values must be a single Unicode character or a WebDriver “special key” (e.g.""for Enter).- Returns:
- the key value, or
nullif unset or not applicable
-
setValue
Sets the key value for a keyboard action.- Parameters:
value- The key value to send. Must be a single Unicode code point or a WebDriver special key constant. Ignored for non-keyboard actions.
-
getPointerType
Returns the pointer type for this action.Applicable to pointer actions, this identifies the input device type:
"mouse""touch""pen"
- Returns:
- the pointer type, or
nullif not set or not a pointer action
-
setPointerType
Sets the pointer type for this action.- Parameters:
pointerType- One of"mouse","touch", or"pen". Required for pointer actions such aspointerDown.
-
getButton
Returns the pointer button associated with apointerDownorpointerUpaction.Button mapping follows the WebDriver spec:
- 0 — left button
- 1 — middle button
- 2 — right button
- Returns:
- the pointer button, or
nullif unset or not applicable
-
setButton
public void setButton(int button) Sets the pointer button forpointerDownorpointerUp.- Parameters:
button- Must be 0, 1, or 2 as defined by the WebDriver Actions specification.
-
getDomElement
Returns the DOM element associated with this action, if any.Pointer actions such as
pointerMove,pointerDown, andpointerUpmay target a specific element as the “origin” of the action.- Returns:
- the target
DomElement, ornullif not applicable
-
setDomElement
Sets the DOM element associated with this action.For pointer actions, this element becomes the action’s origin.
- Parameters:
domElement- the element associated with this action
-
buildHtmlUnitAction
Converts this WebDriver action object into an HtmlUnit-specific input action.The result depends on the action
typeandsubtype: Pointer actionspointerMove→HtmlUnitInputProcessor.PointerMoveHtmlUnitActionpointerDown→HtmlUnitInputProcessor.PointerDownHtmlUnitActionpointerUp→HtmlUnitInputProcessor.PointerUpHtmlUnitActionpause→null
keyDown→HtmlUnitInputProcessor.KeyDownHtmlUnitActionkeyUp→HtmlUnitInputProcessor.KeyUpHtmlUnitActionpause→null
- Always return
null
- Returns:
- a constructed
HtmlUnitInputProcessor.HtmlUnitAction, ornullif the action represents a pause or a “none” action - Throws:
RuntimeException- if the type or subtype are unrecognized or unsupported
-
toString
Returns a human-readable string describing this action, including all parameters that have been set.
-