Keyboard Actions
Practice keyboard interactions using Selenium WebDriver's Actions class and Keys class.
What You Will Practice
- Press Enter.
- Navigate using Tab.
- Use Escape.
- Use Arrow Keys.
- Select text using Ctrl + A.
- Copy and paste text.
- Practice keyboard shortcuts.
- Use Selenium Keys and Actions.
Enter Key
Type a value and press Enter to submit the input.
element.sendKeys("Selenium", Keys.ENTER);
Tab Key
Move focus from one field to the next using the Tab key.
element.sendKeys(Keys.TAB);
Escape Key
Open the popup and use Escape to close it.
Keyboard Popup
Press Escape to close this popup.
actions.sendKeys(Keys.ESCAPE).perform();
Arrow Keys
Use arrow keys to move the selection around the grid.
Click the grid and use the Arrow Keys.
actions.sendKeys(Keys.ARROWDOWN).perform();
actions.sendKeys(Keys.ARROWRIGHT).perform();
Ctrl + A
Select all text inside the input field using Ctrl + A.
element.sendKeys(Keys.CONTROL, "a");
Copy & Paste
Copy text from one field and paste it into another field.
source.sendKeys(Keys.CONTROL, "a");
source.sendKeys(Keys.CONTROL, "c");
target.sendKeys(Keys.CONTROL, "v");
Keyboard Shortcuts
Practice common keyboard shortcuts used in browser automation.
Selenium Keyboard Commands
element.sendKeys(
Keys.ENTER
);
element.sendKeys(
Keys.TAB
);
actions.sendKeys(
Keys.ESCAPE
).perform();
element.sendKeys(
Keys.CONTROL,
"a"
);
element.sendKeys(
Keys.CONTROL,
"c"
);
element.sendKeys(
Keys.CONTROL,
"v"
);