Keyboard Action
Keyboard Action
Keys.ENTER
Keys.TAB
Keys.ARROW_UP
Keys.ARROW_DOWN
Keys.SHIFT
Keys.CONTROL
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
// Open a website
driver.get("https://www.google.com");
In this example, we use the Actions class to send keyboard events. The method
chord() can be used for key combinations (like Ctrl+A).
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.Set;
In this example:
2. After clicking a link that opens a new window or tab, we retrieve all window
handles.
3. We loop through the handles, switch to the new window, and perform
actions there.
Key Points:
1. Keyboard Actions: The Actions class in Selenium can simulate keyboard
interactions, including special keys and combinations.
2. Sliders: Sliders are moved using the dragAndDropBy() method within the
Actions class to simulate dragging.
3. Tabs & Windows: Use window handles to manage and switch between
multiple browser windows or tabs in Selenium.
This covers the essentials for dealing with keyboard actions, sliders, and
tabs/windows in Selenium with Java. For a real-world scenario, you might need