keyDown and keyUp do in Selenium?keyDown simulates pressing a keyboard key down (holding it), and keyUp simulates releasing that key. They help test keyboard shortcuts or key combinations.
Actions class?Use keyDown(Keys.CONTROL) to press Ctrl, then sendKeys("a") to press A, and finally keyUp(Keys.CONTROL) to release Ctrl.
keyUp after keyDown in tests?Because holding a key down without releasing it can cause unexpected behavior. keyUp ensures the key is released, simulating real user input accurately.
Actions actions = new Actions(driver);
WebElement input = driver.findElement(By.id("inputField"));
actions.click(input)
.keyDown(Keys.SHIFT)
.sendKeys("hello")
.keyUp(Keys.SHIFT)
.perform();This types "HELLO" in uppercase by holding SHIFT.
perform() method in Selenium keyboard actions?perform() executes all the actions built so far. Without calling it, the keyboard actions like keyDown and keyUp won't actually happen.
keyDown() simulates pressing a key down (holding it).
keyDown() to release the key?keyUp() releases the key pressed by keyDown().
Holding SHIFT with keyDown(Keys.SHIFT) makes letters uppercase.
perform() method do in Selenium Actions?perform() runs the actions you have prepared.
The correct constant is Keys.CONTROL.