This test opens Google, clicks the search box, holds Shift while typing 'hello' to get uppercase 'HELLO', then checks if the input value matches.
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class KeyboardActionsTest {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();
try {
driver.get("https://www.google.com");
WebElement searchBox = driver.findElement(By.name("q"));
Actions actions = new Actions(driver);
// Click the search box
searchBox.click();
// Hold SHIFT, type 'hello', release SHIFT
actions.keyDown(Keys.SHIFT).sendKeys("hello").keyUp(Keys.SHIFT).perform();
// Verify the input value is 'HELLO'
String value = searchBox.getAttribute("value");
if ("HELLO".equals(value)) {
System.out.println("Test Passed: Text is uppercase as expected.");
} else {
System.out.println("Test Failed: Text is '" + value + "' instead of 'HELLO'.");
}
} finally {
driver.quit();
}
}
}