Implementation:SeleniumHQ Selenium Keys
| Knowledge Sources | |
|---|---|
| Domains | WebDriver, Browser_Automation |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for simulating non-textual keyboard input provided by the Selenium WebDriver library.
Description
The Keys enum represents pressable keys that are not standard text characters, such as modifier keys (SHIFT, CONTROL, ALT), navigation keys (ARROW_LEFT, PAGE_UP, HOME), function keys (F1 through F12), and numpad keys. Each constant maps to a Unicode Private Use Area (PUA) code point (U+E000 through U+F8FF) used internally by WebDriver to simulate keyboard actions per the W3C WebDriver specification. The enum also provides utility methods for composing key chords (multiple simultaneous key presses) and looking up enum constants by their Unicode character value.
Usage
Import Keys when you need to simulate special keyboard input such as pressing Enter, Tab, modifier key combinations, or function keys through WebElement.sendKeys() or the Actions API.
Code Reference
Source Location
- Repository: SeleniumHQ_Selenium
- File: java/src/org/openqa/selenium/Keys.java
Signature
public enum Keys implements CharSequence {
NULL, CANCEL, HELP, BACK_SPACE, TAB, CLEAR, RETURN, ENTER,
SHIFT, LEFT_SHIFT, CONTROL, LEFT_CONTROL, ALT, LEFT_ALT,
PAUSE, ESCAPE, SPACE, PAGE_UP, PAGE_DOWN, END, HOME,
LEFT, ARROW_LEFT, UP, ARROW_UP, RIGHT, ARROW_RIGHT, DOWN, ARROW_DOWN,
INSERT, DELETE, SEMICOLON, EQUALS,
NUMPAD0, NUMPAD1, NUMPAD2, NUMPAD3, NUMPAD4, NUMPAD5,
NUMPAD6, NUMPAD7, NUMPAD8, NUMPAD9,
MULTIPLY, ADD, SEPARATOR, SUBTRACT, DECIMAL, DIVIDE,
F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12,
META, COMMAND,
RIGHT_SHIFT, RIGHT_CONTROL, RIGHT_ALT, RIGHT_COMMAND,
OPTION, FN, ZENKAKU_HANKAKU;
public int getCodePoint();
public char charAt(int index);
public int length();
public CharSequence subSequence(int start, int end);
public String toString();
public static String chord(CharSequence... value);
public static String chord(Iterable<CharSequence> value);
public static @Nullable Keys getKeyFromUnicode(char key);
}
Import
import org.openqa.selenium.Keys;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| value | CharSequence... | Yes | One or more key constants or strings passed to chord() to compose a simultaneous key combination
|
| key | char | Yes | A Unicode character passed to getKeyFromUnicode() to look up the corresponding Keys constant
|
Outputs
| Name | Type | Description |
|---|---|---|
| chord result | String | A string containing all the provided key characters concatenated together, terminated by Keys.NULL to signal modifier key release |
| getKeyFromUnicode result | Keys | The Keys enum constant matching the given Unicode character, or null if no match is found |
| getCodePoint result | int | The Unicode code point value of the key |
Usage Examples
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
// Press ENTER on a form field
WebElement searchBox = driver.findElement(By.name("q"));
searchBox.sendKeys("Selenium WebDriver" + Keys.ENTER);
// Use a key chord for Ctrl+A (select all)
String selectAll = Keys.chord(Keys.CONTROL, "a");
searchBox.sendKeys(selectAll);
// Press TAB to move to the next form field
searchBox.sendKeys(Keys.TAB);
// Use arrow keys for navigation
WebElement slider = driver.findElement(By.id("slider"));
slider.sendKeys(Keys.ARROW_RIGHT);
// Look up a Keys constant from a Unicode character
Keys key = Keys.getKeyFromUnicode('\uE007');
System.out.println(key); // ENTER