Package org.openqa.selenium.htmlunit
Class HtmlUnitKeyboard
- java.lang.Object
-
- org.openqa.selenium.htmlunit.HtmlUnitKeyboard
-
public class HtmlUnitKeyboard extends Object
Provides keyboard input handling forHtmlUnitDriver. 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisAltPressed()Returns whether the Alt key is currently pressed according to the tracked modifier-key state.booleanisCtrlPressed()Returns whether the Control key is currently pressed according to the tracked modifier-key state.booleanisPressed(char ch)Returns whether the specified character key is currently pressed.booleanisPressed(org.openqa.selenium.Keys keys)Returns whether the specifiedKeysvalue is currently pressed.booleanisShiftPressed()Returns whether the Shift key is currently pressed according to the tracked modifier-key state.voidpressKey(CharSequence keyToPress)Sends a key-down event for the given key sequence to the element currently identified as the active element.voidreleaseKey(CharSequence keyToRelease)Sends a key-up event for the given key sequence to the element currently identified as the active element.voidsendKeys(CharSequence... keysToSend)Sends the given key sequence to the element currently identified as the active element within the driver.
-
-
-
Method Detail
-
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 benull- 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 benull- Throws:
org.openqa.selenium.WebDriverException- if anIOExceptionoccurs 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 benull- Throws:
org.openqa.selenium.WebDriverException- if anIOExceptionoccurs 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:
trueif Shift is pressed,falseotherwise
-
isCtrlPressed
public boolean isCtrlPressed()
Returns whether the Control key is currently pressed according to the tracked modifier-key state.- Returns:
trueif Ctrl is pressed,falseotherwise
-
isAltPressed
public boolean isAltPressed()
Returns whether the Alt key is currently pressed according to the tracked modifier-key state.- Returns:
trueif Alt is pressed,falseotherwise
-
isPressed
public boolean isPressed(char ch)
Returns whether the specified character key is currently pressed.- Parameters:
ch- the character representing the key- Returns:
trueif the key is pressed,falseotherwise
-
isPressed
public boolean isPressed(org.openqa.selenium.Keys keys)
Returns whether the specifiedKeysvalue is currently pressed.- Parameters:
keys- the key to check; must not benull- Returns:
trueif the key is pressed,falseotherwise
-
-