Class Action
- java.lang.Object
-
- org.openqa.selenium.htmlunit.w3.Action
-
public class Action extends Object
An action object constructed with argumentsid,type, andsubtyperepresents 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
typefield corresponds to a WebDriver input source type (e.g."pointer","key","none"). Thesubtypeindicates 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 byHtmlUnitInputProcessor.- Author:
- Ronald Brill
- See Also:
- W3C Action Object definition
- A pointer action with
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HtmlUnitInputProcessor.HtmlUnitActionbuildHtmlUnitAction()Converts this WebDriver action object into an HtmlUnit-specific input action.IntegergetButton()Returns the pointer button associated with apointerDownorpointerUpaction.DomElementgetDomElement()Returns the DOM element associated with this action, if any.IntegergetDuration()Returns the duration associated with this action.StringgetPointerType()Returns the pointer type for this action.StringgetValue()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.voidsetValue(String value)Sets the key value for a keyboard action.StringtoString()Returns a human-readable string describing this action, including all parameters that have been set.
-
-
-
Constructor Detail
-
Action
public Action(String id, String type, String subtype)
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 Detail
-
getDuration
public Integer 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
public String 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
public void setValue(String value)
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
public String 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
public void setPointerType(String pointerType)
Sets the pointer type for this action.- Parameters:
pointerType- One of"mouse","touch", or"pen". Required for pointer actions such aspointerDown.
-
getButton
public Integer 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
public DomElement 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
public void setDomElement(DomElement domElement)
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
public HtmlUnitInputProcessor.HtmlUnitAction 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
-
-