Challenge - 5 Problems
Keyboard Actions Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Selenium Java code snippet?
Consider the following Selenium Java code that performs keyboard actions on a web element. What will be the final text input in the field after execution?
Selenium Java
WebElement input = driver.findElement(By.id("username")); Actions actions = new Actions(driver); actions.keyDown(Keys.SHIFT).sendKeys(input, "hello").keyUp(Keys.SHIFT).perform();
Attempts:
2 left
💡 Hint
Remember what holding down the SHIFT key does to letters when typing.
✗ Incorrect
Holding down the SHIFT key while sending keys converts letters to uppercase. Since keyDown(Keys.SHIFT) is active during sendKeys, all letters are uppercase.
❓ assertion
intermediate2:00remaining
Which assertion correctly verifies that SHIFT key was released after typing?
You want to assert that after performing keyDown(Keys.SHIFT) and sendKeys, the SHIFT key is no longer pressed. Which assertion is valid in Selenium Java?
Selenium Java
Actions actions = new Actions(driver);
actions.keyDown(Keys.SHIFT).sendKeys("test").keyUp(Keys.SHIFT).perform();Attempts:
2 left
💡 Hint
Check if the SHIFT key is pressed or not after keyUp.
✗ Incorrect
After keyUp(Keys.SHIFT), the SHIFT key should not be pressed, so isShiftDown() should return false.
🔧 Debug
advanced2:00remaining
Why does this Selenium Java code throw an exception?
Examine the code below. It throws an exception at runtime. What is the cause?
Selenium Java
WebElement input = driver.findElement(By.id("inputField")); Actions actions = new Actions(driver); actions.keyDown(Keys.CONTROL).sendKeys("a").perform(); actions.keyUp(Keys.CONTROL).perform();
Attempts:
2 left
💡 Hint
Check how keyDown and keyUp are chained in Actions.
✗ Incorrect
keyDown and keyUp should be chained in the same Actions sequence before calling perform(). Calling perform() after keyDown and then again after keyUp breaks the sequence and causes an exception.
🧠 Conceptual
advanced2:00remaining
What is the main difference between keyDown and sendKeys in Selenium Actions?
Choose the best explanation of how keyDown and sendKeys differ in Selenium Actions.
Attempts:
2 left
💡 Hint
Think about holding keys vs typing characters.
✗ Incorrect
keyDown simulates pressing and holding a key (like SHIFT), while sendKeys sends characters or key presses to the element.
❓ framework
expert3:00remaining
In a Selenium Java test framework, how to best implement a reusable method for typing uppercase text using keyboard actions?
You want a reusable method that types a given string in uppercase by holding SHIFT using Selenium Actions. Which method implementation is correct and efficient?
Selenium Java
public void typeUppercase(WebElement element, String text) {
Actions actions = new Actions(driver);
// fill in
}Attempts:
2 left
💡 Hint
SHIFT key changes letter case during typing; no need to convert string manually.
✗ Incorrect
Holding SHIFT while sending keys types uppercase letters automatically, so sending the original text with SHIFT held is best. Option D sends already uppercase text with SHIFT, resulting in wrong characters.