The industry-standard framework for browser automation. Control any browser, simulate real user interactions, and build rock-solid test suites with Java.
WebDriver sends commands to browsers through the W3C WebDriver protocol — the same standard your real users interact with.
Author Java/Python/JS tests using WebDriver API calls and assertions
Commands sent as HTTP/JSON to browser driver via W3C standard
ChromeDriver / GeckoDriver translates commands to native APIs
Real browser navigates, clicks, types — exactly like a human would
Verify DOM state, page title, element visibility, URL — tests pass/fail
Selenium is a suite of tools. Understanding each layer unlocks powerful, scalable automation.
The heart of Selenium. Provides browser.findElement(), click(), sendKeys(), navigate() and 100+ methods to control browsers programmatically.
Platform-specific executables that implement W3C WebDriver spec. ChromeDriver for Chrome, GeckoDriver for Firefox, SafariDriver for Safari.
8 ways to find elements: ID (fastest), CSS Selector (recommended), XPath (powerful), Name, Class, Tag, Link Text, Partial Link Text.
Three types: Implicit (global), Explicit (condition-based), Fluent (polling interval). Always prefer Explicit Waits for reliable tests.
Design pattern that creates an object repository for web elements. Each page has a class — locators and actions are encapsulated. Tests become shorter, readable, and maintainable. The gold standard for enterprise test automation.
Master these methods and you can automate almost anything in a browser.
// Page Object Model — encapsulates page logic
public class LoginPage {
private WebDriver driver;
private WebDriverWait wait;
@FindBy(id = "username")
private WebElement usernameInput;
@FindBy(id = "password")
private WebElement passwordInput;
@FindBy(css = ".login-btn")
private WebElement loginButton;
@FindBy(css = ".error-message")
private WebElement errorMsg;
public LoginPage(WebDriver driver) {
this.driver = driver;
this.wait = new WebDriverWait(driver, Duration.ofSeconds(10));
PageFactory.initElements(driver, this);
}
public DashboardPage login(String user, String pass) {
wait.until(ExpectedConditions.visibilityOf(usernameInput));
usernameInput.clear();
usernameInput.sendKeys(user);
passwordInput.sendKeys(pass);
loginButton.click();
return new DashboardPage(driver);
}
public String getErrorMessage() {
wait.until(ExpectedConditions.visibilityOf(errorMsg));
return errorMsg.getText();
}
}
Watch Selenium control a browser in real-time. Pick a scenario and hit Run to see it execute step by step.
How Selenium stacks up against modern alternatives.
| Feature | Selenium 4 | Playwright | Cypress | Puppeteer |
|---|---|---|---|---|
| Multi-browser | All | All | Limited | Chromium |
| Language Support | Java, Python, JS, C#, Ruby | JS/TS, Python, Java, C# | JS/TS only | JS/TS only |
| Grid / Parallel | Selenium Grid 4 | Built-in | Cypress Cloud | Manual |
| Real Browser | Always | Always | Always | Chromium |
| Maturity | 20+ years | 4 years | 7 years | 6 years |
| Enterprise Adoption | Highest | High | Medium | Low |
| Auto-Wait | Manual (Explicit) | Built-in | Built-in | Manual |
| Mobile Testing | Appium | Emulation | Emulation | No |
Add selenium-java 4.x + WebDriverManager to pom.xml for automatic driver management
WebDriverManager.chromedriver().setup() — handles driver download automatically
ChromeOptions for headless, window size, user agent, and performance flags
@BeforeMethod launches browser, @AfterMethod quits — inherited by all tests
Create a class per page, use @FindBy + PageFactory for element management
@Test methods call page object methods — tests read like plain English
Allure or ExtentReports for HTML reports with screenshots on failure
mvn test in GitHub Actions / Jenkins — headless Chrome runs anywhere
<!-- Selenium WebDriver 4 -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.18.1</version>
</dependency>
<!-- WebDriverManager — auto driver download -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.7.0</version>
</dependency>
<!-- TestNG test framework -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.9.0</version>
</dependency>
<!-- Allure reporting -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-testng</artifactId>
<version>2.25.0</version>
</dependency>