Class Action


  • public class Action
    extends Object
    An action object constructed with arguments 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:
    W3C Action Object definition
    • 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 null if 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 keyDown or keyUp. Values must be a single Unicode character or a WebDriver “special key” (e.g. "" for Enter).

        Returns:
        the key value, or null if 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 null if 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 as pointerDown.
      • getButton

        public Integer getButton()
        Returns the pointer button associated with a pointerDown or pointerUp action.

        Button mapping follows the WebDriver spec:

        • 0 — left button
        • 1 — middle button
        • 2 — right button
        Returns:
        the pointer button, or null if unset or not applicable
      • setButton

        public void setButton​(int button)
        Sets the pointer button for pointerDown or pointerUp.
        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, and pointerUp may target a specific element as the “origin” of the action.

        Returns:
        the target DomElement, or null if 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
      • toString

        public String toString()
        Returns a human-readable string describing this action, including all parameters that have been set.
        Overrides:
        toString in class Object
        Returns:
        a descriptive string representation of this action