Browser Automation Framework

Master Selenium WebDriver

The industry-standard framework for browser automation. Control any browser, simulate real user interactions, and build rock-solid test suites with Java.

0
Browsers
0
Years Old
0
GitHub Stars
0
Scenarios
Cross-Browser Testing
WebDriver Protocol
Element Locators
Explicit Waits
Screenshot Capture
Actions API
Chrome / Firefox / Safari
Page Object Model
XPath & CSS Selectors
JavaScript Executor
Grid Parallel Execution
TestNG Integration
Cross-Browser Testing
WebDriver Protocol
Element Locators
Explicit Waits
Screenshot Capture
Actions API
Chrome / Firefox / Safari
Page Object Model
XPath & CSS Selectors
JavaScript Executor
Grid Parallel Execution
TestNG Integration
01 — Overview

How Selenium Works

WebDriver sends commands to browsers through the W3C WebDriver protocol — the same standard your real users interact with.

01
Author

Write Test Code

Author Java/Python/JS tests using WebDriver API calls and assertions

→
02
Protocol

WebDriver Protocol

Commands sent as HTTP/JSON to browser driver via W3C standard

→
03
Driver

Browser Driver

ChromeDriver / GeckoDriver translates commands to native APIs

→
04
Execute

Browser Executes

Real browser navigates, clicks, types — exactly like a human would

→
05
Verify

Assert Results

Verify DOM state, page title, element visibility, URL — tests pass/fail

02 — Architecture

Core Components

Selenium is a suite of tools. Understanding each layer unlocks powerful, scalable automation.

Core API

WebDriver API

The heart of Selenium. Provides browser.findElement(), click(), sendKeys(), navigate() and 100+ methods to control browsers programmatically.

findElement() click() sendKeys() navigate() executeScript()
Drivers

Browser Drivers

Platform-specific executables that implement W3C WebDriver spec. ChromeDriver for Chrome, GeckoDriver for Firefox, SafariDriver for Safari.

ChromeDriver GeckoDriver SafariDriver EdgeDriver
Locators

Locator Strategies

8 ways to find elements: ID (fastest), CSS Selector (recommended), XPath (powerful), Name, Class, Tag, Link Text, Partial Link Text.

By.id() By.cssSelector() By.xpath() By.name() By.className()
Waits

Wait Strategies

Three types: Implicit (global), Explicit (condition-based), Fluent (polling interval). Always prefer Explicit Waits for reliable tests.

Implicit Wait Explicit Wait * Fluent Wait WebDriverWait
Design Pattern

Page Object Model (POM)

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.

@FindBy PageFactory BasePage LoginPage DashboardPage Reusable Actions Separation of Concerns
03 — Key Concepts

Essential WebDriver Methods

Master these methods and you can automate almost anything in a browser.

driver.get(url)
Navigate to a URL and wait for page load to complete
findElement(By)
Locate a single DOM element using any locator strategy
element.click()
Simulate a real mouse click on any interactable element
sendKeys(text)
Type text into input fields, simulate key presses
getText()
Retrieve visible text content of an element
WebDriverWait
Wait until ExpectedCondition is met — no flaky sleeps
Actions API
Hover, drag-drop, double-click, right-click, keyboard chords
executeScript()
Run arbitrary JavaScript — scroll, modify DOM, get JS values
getScreenshotAs()
Capture full-page or element screenshots on failure
Sample Code

Page Object Model

LoginPage.java — Page Object Pattern
// 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();
    }
}
04 — Interactive Playground

Browser Automation Simulator

Watch Selenium control a browser in real-time. Pick a scenario and hit Run to see it execute step by step.

Selenium WebDriver Lab
6 scenarios · animated browser · live execution logs
LIVE Java + WebDriver 4 POM Pattern
Test Scenarios
Speed: 1x
Ready — Select a scenario and press Run
0steps
0.0selapsed
0assertions
Execution Log
05 — Comparison

Selenium vs The World

How Selenium stacks up against modern alternatives.

Feature Selenium 4 Playwright Cypress Puppeteer
Multi-browserAllAllLimitedChromium
Language SupportJava, Python, JS, C#, RubyJS/TS, Python, Java, C#JS/TS onlyJS/TS only
Grid / ParallelSelenium Grid 4Built-inCypress CloudManual
Real BrowserAlwaysAlwaysAlwaysChromium
Maturity20+ years4 years7 years6 years
Enterprise AdoptionHighestHighMediumLow
Auto-WaitManual (Explicit)Built-inBuilt-inManual
Mobile TestingAppiumEmulationEmulationNo
06 — Setup Guide

Get Running in 5 Minutes

1

Add Maven Dependency

Add selenium-java 4.x + WebDriverManager to pom.xml for automatic driver management

2

Configure WebDriver

WebDriverManager.chromedriver().setup() — handles driver download automatically

3

Set Browser Options

ChromeOptions for headless, window size, user agent, and performance flags

4

Create Base Test Class

@BeforeMethod launches browser, @AfterMethod quits — inherited by all tests

5

Implement Page Objects

Create a class per page, use @FindBy + PageFactory for element management

6

Write Test Cases

@Test methods call page object methods — tests read like plain English

7

Add Reporting

Allure or ExtentReports for HTML reports with screenshots on failure

8

CI/CD Integration

mvn test in GitHub Actions / Jenkins — headless Chrome runs anywhere

pom.xml — Maven Dependencies
<!-- 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>