Forms, Dropdowns, Checkboxes, Radio Buttons, and Alerts
Automate the common interactive controls that appear in real web applications and build reliable validation around them.
Inside this chapter
- Form Automation Basics
- Dropdown Example
- Checkboxes and Radio Buttons
- JavaScript Alerts
- Validation Testing
- Business Example
Series navigation
Study the chapters in order for the clearest path from Selenium setup and locators to framework design, CI integration, flaky-test control, and advanced automation engineering practice. Use the navigation at the bottom to move smoothly through the full tutorial series.
Form Automation Basics
Many UI tests revolve around forms: login, signup, profile updates, address entry, payment details, search filters, and admin actions. Selenium must handle these interactions predictably and verify both valid and invalid workflows.
Dropdown Example
Select country = new Select(driver.findElement(By.id("country")));
country.selectByVisibleText("India");
Dropdown handling looks simple, but real systems may use custom dropdown widgets that require a different strategy from standard HTML select elements.
Checkboxes and Radio Buttons
WebElement terms = driver.findElement(By.id("acceptTerms"));
if (!terms.isSelected()) {
terms.click();
}
Tests should verify state intentionally rather than clicking blindly.
JavaScript Alerts
Alert alert = driver.switchTo().alert();
System.out.println(alert.getText());
alert.accept(); Validation Testing
Strong form tests verify both success and error behavior: missing required fields, invalid formats, password rules, disabled submission, duplicate records, and role-specific permissions.
Business Example
An insurance portal may have long policy forms with conditional questions, validation messages, and confirmation alerts. Automating such workflows requires both control-handling skill and thoughtful assertion design.