Class HtmlUnitKeyboard

java.lang.Object
org.openqa.selenium.htmlunit.HtmlUnitKeyboard

public class HtmlUnitKeyboard extends Object
Provides keyboard input handling for HtmlUnitDriver. This class manages modifier-key state, dispatches key events to HtmlUnit DOM elements, and coordinates focus changes when sending keyboard input.

Instances of this class are typically accessed through the driver’s input device system rather than created directly.

Author:
Alexei Barantsev, Ahmed Ashour, Simon Stewart, Glib Briia, Ronald Brill, Martin Bartoš
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns whether the Alt key is currently pressed according to the tracked modifier-key state.
    boolean
    Returns whether the Control key is currently pressed according to the tracked modifier-key state.
    boolean
    isPressed(char ch)
    Returns whether the specified character key is currently pressed.
    boolean
    isPressed(org.openqa.selenium.Keys keys)
    Returns whether the specified Keys value is currently pressed.
    boolean
    Returns whether the Shift key is currently pressed according to the tracked modifier-key state.
    void
    pressKey(CharSequence keyToPress)
    Sends a key-down event for the given key sequence to the element currently identified as the active element.
    void
    releaseKey(CharSequence keyToRelease)
    Sends a key-up event for the given key sequence to the element currently identified as the active element.
    void
    sendKeys(CharSequence... keysToSend)
    Sends the given key sequence to the element currently identified as the active element within the driver.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • sendKeys

      public void sendKeys(CharSequence... keysToSend)
      Sends the given key sequence to the element currently identified as the active element within the driver. The keys are dispatched according to HtmlUnit’s keyboard event model, and modifier-key state is updated as needed.
      Parameters:
      keysToSend - one or more character sequences to send as key input; must not be null
      Throws:
      org.openqa.selenium.NoSuchElementException - if there is no active element
    • pressKey

      public void pressKey(CharSequence keyToPress)
      Sends a key-down event for the given key sequence to the element currently identified as the active element. This method triggers HtmlUnit's low-level keyboard event processing and updates the internal modifier-key state.
      Parameters:
      keyToPress - the key or key sequence to press; must not be null
      Throws:
      org.openqa.selenium.WebDriverException - if an IOException occurs while dispatching the key event
    • releaseKey

      public void releaseKey(CharSequence keyToRelease)
      Sends a key-up event for the given key sequence to the element currently identified as the active element. This method triggers HtmlUnit's low-level keyboard event processing and updates the internal modifier-key state.
      Parameters:
      keyToRelease - the key or key sequence to release; must not be null
      Throws:
      org.openqa.selenium.WebDriverException - if an IOException occurs while dispatching the key event
    • isShiftPressed

      public boolean isShiftPressed()
      Returns whether the Shift key is currently pressed according to the tracked modifier-key state.
      Returns:
      true if Shift is pressed, false otherwise
    • isCtrlPressed

      public boolean isCtrlPressed()
      Returns whether the Control key is currently pressed according to the tracked modifier-key state.
      Returns:
      true if Ctrl is pressed, false otherwise
    • isAltPressed

      public boolean isAltPressed()
      Returns whether the Alt key is currently pressed according to the tracked modifier-key state.
      Returns:
      true if Alt is pressed, false otherwise
    • isPressed

      public boolean isPressed(char ch)
      Returns whether the specified character key is currently pressed.
      Parameters:
      ch - the character representing the key
      Returns:
      true if the key is pressed, false otherwise
    • isPressed

      public boolean isPressed(org.openqa.selenium.Keys keys)
      Returns whether the specified Keys value is currently pressed.
      Parameters:
      keys - the key to check; must not be null
      Returns:
      true if the key is pressed, false otherwise