Selenium WebDriver is an open-source library for automating web browsers. Your test code sends commands — open this page, type here, click that — and WebDriver makes a real browser carry them out. It is the core of the Selenium project and one of the most widely used tools in test automation.
This guide explains what WebDriver is, how its architecture works in Selenium 4, how its interfaces and classes fit together, and how to write and run your first script. It is updated for modern Selenium: the W3C WebDriver protocol and automatic driver management with Selenium Manager.
What Is Selenium WebDriver?
WebDriver is a collection of language bindings (APIs) that control browsers the way a user would. Its interface lets you:
- Find and interact with web elements — type, click, select, read text.
- Navigate between pages, go back and forward, refresh.
- Manage windows, tabs, frames, cookies and timeouts.
- Handle JavaScript alerts, take screenshots and run JavaScript.
It supports Chrome, Firefox, Edge and Safari, and you can write tests in Java, Python, C#, JavaScript and Ruby (the officially supported bindings).
The Selenium suite
- Selenium WebDriver — the automation API you write code against (this guide).
- Selenium IDE — a browser extension that records and plays back actions, useful for quick prototypes.
- Selenium Grid — runs tests on many browsers and machines in parallel. See Parallel Execution, Grid & Cross-Browser Testing and the Docker + Selenium Grid Guide.
Why Selenium WebDriver Is Popular
- Free and open source — no licence cost, with a large community.
- Multiple languages — teams can use the language they already know.
- Cross-browser — the same test runs on Chrome, Firefox, Edge and Safari.
- Cross-platform — Windows, macOS and Linux.
- A W3C standard — the WebDriver protocol is an official web standard that browser vendors implement themselves, so browser support is reliable.
- Huge ecosystem — TestNG, JUnit, Cucumber, Extent Reports, Maven, Jenkins and cloud grids all integrate with it.
Selenium WebDriver Architecture
In Selenium 4 there are four parts, and every command passes through them in order:
Test script → Selenium client library → Browser driver → Browser
- Test script — your code, for example
driver.findElement(By.id("login")).click(); - Selenium client library (language binding) — converts each call into a request in the W3C WebDriver protocol: JSON sent over HTTP.
- Browser driver — ChromeDriver, GeckoDriver (Firefox), EdgeDriver or SafariDriver. It runs a small local server, receives the request and translates it into the browser's own internal commands.
- Browser — performs the action and returns the result, which travels back the same way as an HTTP response.
What changed from older Selenium: Selenium 3 and earlier used the JSON Wire Protocol, which needed extra translation between Selenium and each browser. Selenium 4 speaks the W3C WebDriver protocol directly, which browser vendors implement, making communication more consistent. Selenium 4 is also adding WebDriver BiDi, a newer two-way protocol for features like listening to console logs and network events.
The letter analogy
- You write a letter → test script
- The post office puts it in a standard envelope → client library (W3C format)
- The local postman delivers it → browser driver
- Your friend reads it and replies → browser
A login test, step by step
- Your Java code calls
sendKeys()on the username field. - The Java client library sends an HTTP request to ChromeDriver: "send these keys to element X".
- ChromeDriver tells Chrome to type into that element.
- Chrome types the text and ChromeDriver returns a success response.
- The same round trip happens for the password and the login click.
Interview answer
"In Selenium 4, the test script calls the WebDriver API in its language binding. The client library converts each command into a W3C WebDriver protocol request — JSON over HTTP — and sends it to the browser driver, such as ChromeDriver. The driver translates it into native browser commands, the browser performs the action, and the response travels back to the script. Older versions used the JSON Wire Protocol instead."
How Selenium Supports Multiple Browsers
Each browser has its own driver that implements the same W3C standard, so your test code stays the same and only the driver class changes:
| Browser | Driver | Java class |
|---|---|---|
| Chrome | ChromeDriver | ChromeDriver |
| Firefox | GeckoDriver | FirefoxDriver |
| Edge | EdgeDriver (msedgedriver) | EdgeDriver |
| Safari | SafariDriver (built into macOS) | SafariDriver |
Internet Explorer is retired and no longer a target for new automation — use Edge instead.
The WebDriver Class Hierarchy
Is WebDriver a class or an interface?
WebDriver is an interface. It declares methods such as get(), findElement(), navigate(), manage(), switchTo(), close() and quit(), and browser-specific classes implement them.
The super interface: SearchContext
WebDriver extends SearchContext, which declares just two methods:
findElement(By by)— returns the first matching element, or throwsNoSuchElementException.findElements(By by)— returns a list of all matches, or an empty list.
WebElement also extends SearchContext, which is why you can search inside an element — for example, find the cells inside one table row.
From interface to browser class
SearchContext → WebDriver → implemented by RemoteWebDriver → extended by ChromiumDriver → extended by ChromeDriver and EdgeDriver. FirefoxDriver and SafariDriver extend RemoteWebDriver directly.
RemoteWebDriver also implements interfaces such as JavascriptExecutor and TakesScreenshot. That's why we write WebDriver driver = new ChromeDriver(); (upcasting, so the same code works for any browser) and cast when we need those extra abilities: ((JavascriptExecutor) driver).executeScript(...). More in JavaScriptExecutor & Typecasting.
Selenium Versions: From RC to Selenium 4
| Version | Key points |
|---|---|
| Selenium 1 (RC) | JavaScript injected into the browser; required the Selenium RC server as a proxy; slow and limited. |
| Selenium 2 | Introduced WebDriver: direct browser control through drivers, no proxy server, much faster. |
| Selenium 3 | Removed the old RC API; browser vendors began shipping their own drivers; JSON Wire Protocol. |
| Selenium 4 | W3C WebDriver protocol, relative locators, new window/tab API, Chrome DevTools access, rebuilt Grid, and Selenium Manager for automatic driver setup. |
Prerequisites
- JDK (Java 11 or newer).
- An IDE — IntelliJ IDEA, Eclipse or VS Code.
- Maven (or Gradle) to download Selenium — see Maven for Selenium.
- A browser installed on the machine.
You no longer need to download browser drivers manually. Since Selenium 4.6, Selenium Manager detects your browser version and downloads the matching driver automatically.
Your First Selenium 4 Script
Add the Selenium dependency to pom.xml (use the latest 4.x version from Maven Central):
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.25.0</version>
</dependency>
This script uses Selenium's own demo form: it types into a text box, submits the form, and prints the confirmation message.
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class FirstTest {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver(); // Selenium Manager finds the right driver
try {
driver.manage().window().maximize();
driver.get("https://www.selenium.dev/selenium/web/web-form.html");
driver.findElement(By.name("my-text")).sendKeys("Selenium");
driver.findElement(By.cssSelector("button")).click();
WebElement message = new WebDriverWait(driver, Duration.ofSeconds(5))
.until(ExpectedConditions.visibilityOfElementLocated(By.id("message")));
System.out.println(message.getText()); // Received!
} finally {
driver.quit(); // always close the browser, even if the test fails
}
}
}
If you see an old tutorial using System.setProperty("webdriver.chrome.driver", "path/to/chromedriver"), you can drop that line — hard-coded driver paths are a common cause of SessionNotCreatedException when the browser updates.
close() vs quit()
driver.close()closes only the current window or tab.driver.quit()closes every window and ends the WebDriver session. Use it in your teardown so no browser processes are left running.
The Basic Automation Flow
- Create a WebDriver object (this launches the browser).
- Open the application with
driver.get(). - Locate elements with locators (ID, name, CSS, XPath).
- Perform actions —
sendKeys(),click(), select options. - Wait for the result with explicit waits, never fixed sleeps.
- Validate the result with assertions (TestNG or JUnit).
- Close the browser with
quit().
See each step in action in the Selenium WebDriver Visualizer, and practise the commands in WebElement & Browser Commands.
Limitations of Selenium WebDriver
- Web applications only — no desktop apps. For mobile apps, use Appium, which builds on the WebDriver protocol.
- No built-in test runner or reports — pair it with TestNG or JUnit, and Extent Reports or Allure.
- No API testing — use REST Assured or Postman for web services.
- No OS-level dialogs — native Windows pop-ups need tools like AutoIt or the Robot class; browser file uploads usually work with
sendKeys()on the file input. - CAPTCHA and OTP — deliberately designed to block automation. Ask for test-environment bypasses or test OTP values instead.
- Image, audio and video validation — needs additional tools.
- Requires programming skills and careful synchronisation to avoid flaky tests — see Selenium Errors & Exceptions.
Testing Types Selenium Supports
Selenium is used for functional, regression, smoke and cross-browser testing of web applications — anywhere you need to repeat real user journeys reliably.
From Real Projects
I've used Selenium WebDriver with Java and TestNG on Canolog, an automotive dealership management system, and on Testsigma. Understanding how WebDriver talks to the browser made debugging much easier when the same test behaved differently on Chrome and Firefox during cross-browser execution. In our hybrid framework, WebDriver calls lived inside POM classes and a business library, so test scripts read like business steps and a change in the application only needed a fix in one place.
Frequently Asked Questions
What is Selenium WebDriver?
An open-source library of language bindings that automates real web browsers for testing, across Chrome, Firefox, Edge and Safari and languages such as Java, Python, C#, JavaScript and Ruby.
What is Selenium WebDriver architecture?
Test script → client library → browser driver → browser. In Selenium 4, commands travel as W3C WebDriver protocol requests (JSON over HTTP); Selenium 3 used the JSON Wire Protocol.
Is WebDriver a class or an interface?
An interface. Classes such as ChromeDriver, FirefoxDriver, EdgeDriver and SafariDriver implement it, mostly through RemoteWebDriver.
What is the super interface of WebDriver?
SearchContext, which declares findElement() and findElements(). WebElement extends it too, so you can search inside an element.
Do I still need to download ChromeDriver?
No. Since Selenium 4.6, Selenium Manager downloads the correct driver automatically. Keep your Selenium dependency up to date and remove hard-coded driver paths.
What is the difference between close() and quit()?
close() closes the current window; quit() closes all windows and ends the session.
What is new in Selenium 4?
The W3C WebDriver protocol, relative locators, a new window and tab API, Chrome DevTools access, a redesigned Grid and Selenium Manager.
Can Selenium automate CAPTCHA?
No. CAPTCHA exists to block automation. In test environments, teams disable it or use test keys instead.
Next Steps
- The Complete Selenium WebDriver Guide — the full learning path
- Selenium Locators and XPath and the Selector Playground
- Browser Launch & Setup Practice — 100+ exercises
- Selenium Interview Questions