What Is Selenium Webdriver?
Selenium WebDriver is the open-source standard for automating web browsers. Paired with Java, TestNG and Maven, it powers a large share of UI test automation in real companies — driving Chrome, Firefox, Edge and Safari through the W3C WebDriver protocol. This guide is your complete learning path: the essentials on one page, a first test and a first page object, then every tutorial on the site in the order you should learn it.
What You'll Learn
- How Selenium works, and how to set up a Selenium 4 project with Maven.
- Locators, waits, forms, alerts, frames, windows, Actions and JavaScriptExecutor.
- TestNG, the Page Object Model, data-driven testing, Grid and CI with Jenkins.
- How to troubleshoot the common exceptions — and how to explain all of it in an interview.
Selenium in 5 Minutes
The Selenium suite
- WebDriver — the API you write tests against. This is what "Selenium" usually means.
- Grid — runs tests on many browsers and machines in parallel.
- IDE — a browser extension that records and plays back actions, for quick prototypes.
How a command travels
Your test → Selenium client library → browser driver (ChromeDriver, GeckoDriver…) → browser.
Each call such as click() becomes a W3C WebDriver request (JSON over HTTP) that the driver turns into a real browser action. Full explanation: Selenium WebDriver Fundamentals.
The tech stack you'll use
| Layer | Tool |
|---|---|
| Language | Java |
| Browser automation | Selenium WebDriver 4 |
| Test runner & assertions | TestNG (or JUnit) |
| Build & dependencies | Maven |
| Design pattern | Page Object Model |
| Reporting | Extent Reports or Allure |
| CI/CD & scale | Git, Jenkins, Selenium Grid / Docker |
Your First Selenium Test (With TestNG)
Add selenium-java and testng to your pom.xml. From Selenium 4.6 you don't need to download ChromeDriver — Selenium Manager does it automatically. This test uses Selenium's own demo form:
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class WebFormTest {
private WebDriver driver;
@BeforeMethod
public void setUp() {
driver = new ChromeDriver();
driver.manage().window().maximize();
}
@Test
public void submitsTheForm() {
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();
String message = new WebDriverWait(driver, Duration.ofSeconds(5))
.until(ExpectedConditions.visibilityOfElementLocated(By.id("message")))
.getText();
Assert.assertEquals(message, "Received!");
}
@AfterMethod
public void tearDown() {
if (driver != null) driver.quit();
}
}
Run it with mvn test. Three habits to keep from day one: explicit waits instead of sleeps, assertions on every test, and quit() in teardown.
From Test to Framework: the Page Object Model
As tests grow, locators and actions move into page classes so each change is made in one place:
public class LoginPage {
private final WebDriver driver;
private final By username = By.id("username");
private final By password = By.id("password");
private final By loginButton = By.cssSelector("button[type='submit']");
public LoginPage(WebDriver driver) { this.driver = driver; }
public void loginAs(String user, String pass) {
driver.findElement(username).sendKeys(user);
driver.findElement(password).sendKeys(pass);
driver.findElement(loginButton).click();
}
}
// In the test:
new LoginPage(driver).loginAs("standard_user", "secret_sauce");
Storing By locators (not WebElements) also prevents stale element failures. Next steps: Frameworks & Page Object Model and The Complete Automation Framework Guide.
The Learning Path
Part 1 — Fundamentals
- Selenium WebDriver Fundamentals — architecture, the WebDriver interface, drivers and your first script.
- Locators & XPath — all 8 locator strategies, CSS selectors, absolute vs relative XPath.
- WebElement & Browser Commands — click, sendKeys, getText and navigation.
- Waits & Synchronization — implicit, explicit and fluent waits: the number-one cause of flaky tests.
Part 2 — Interacting With Web Pages
- Form Elements — text fields, checkboxes, radio buttons, the Select class, uploads.
- Alerts, Frames & Windows — JavaScript alerts, iframes and multiple tabs.
- The Actions Class — hover, drag-and-drop, right-click, double-click.
- JavaScriptExecutor & Type Casting — scrolling and JS when standard commands fall short.
- Advanced Element Handling — AJAX, hidden and dynamic elements, broken links.
Part 3 — Test Management & Execution
- TestNG Essentials — annotations, assertions, groups, priorities, DataProvider and testng.xml.
- Parallel, Grid & Cross-Browser — ThreadLocal drivers, Selenium Grid and cross-browser runs.
- Maven & CI/CD — dependencies, the build lifecycle and Jenkins.
- Docker + Selenium Grid — reproducible browsers for CI.
Part 4 — Frameworks & Design
- Java for Selenium — OOP, collections and exceptions behind every framework.
- Frameworks & Page Object Model — framework types, POM and Page Factory.
- Data-Driven Testing — Excel with Apache POI, properties files and JSON.
- E-Commerce Framework, Step by Step — a complete framework build.
Part 5 — Troubleshooting
When something breaks, start with the Selenium Errors & Exceptions guide ⭐, or go straight to the error:
- NoSuchElementException — unable to locate element
- StaleElementReferenceException — element not attached to the page
- Element Not Clickable at Point — another element would receive the click
- TimeoutException & ElementNotInteractable
- SessionNotCreatedException — driver version mismatch
- NullPointerException with PageFactory
- Passes Locally, Fails in Jenkins — CI-only failures
Or paste any error into the Selenium Exception Lookup.
Part 6 — Hands-On Practice
- The Complete Selenium Practice Roadmap ⭐ — 34 exercises, start here
- Browser Launch & Setup · Locators (with solutions) · WebElement Actions
- Text Boxes, Radio & Checkboxes · Dropdowns · Alerts & Popups
- Frames & iFrames · Windows, Tabs & Waits · Actions & JavaScriptExecutor
- Practise on the Automation Practice Hub, and test selectors in the Selector Playground.
Part 7 — Interview & Project Readiness
- Top 50 Selenium Interview Questions and the Selenium Interview Simulator
- Scenario-Based Selenium Questions
- Project, Process & Estimation — explaining your project and effort estimates
- Explain Your Automation Framework — the round that decides most interviews
An 8-Week Learning Plan
| Week | Focus | Outcome |
|---|---|---|
| 1 | Core Java refresher, Maven, first script | A test that opens a page and asserts on it |
| 2 | Locators and XPath | Write stable locators for any element |
| 3 | Waits, forms, dropdowns | Reliable tests with no sleeps |
| 4 | Alerts, frames, windows, Actions | Handle every common UI control |
| 5 | TestNG: annotations, groups, DataProvider | An organised, data-driven suite |
| 6 | Page Object Model and utilities | A small, maintainable framework |
| 7 | Parallel runs, Grid/Docker, Jenkins | The suite running in CI |
| 8 | Troubleshooting and interview prep | Explain your framework confidently |
Put the framework on GitHub as you build it — it becomes your portfolio. For the full career path, see 0 to SDET in 6 Months.
Selenium or Playwright?
Learn Selenium first if you're targeting Java automation roles — it's still the most common tool in enterprise projects and interviews. Learn Playwright next: it has built-in auto-waiting, a test runner and strong debugging tools, and many new projects use it. Compare them in Selenium vs Playwright, or convert code with the Framework Translator.
How to Use This Guide
- Beginners: follow Parts 1 → 4 in order, practising each topic in Part 6 as you go.
- Framework builders: focus on Parts 3 and 4, then the data-driven tutorial.
- Interview prep: start with Part 7, revise Parts 1–2 for "write code" rounds and Part 4 for the "explain your framework" round.
- Something broken right now: jump to Part 5.
For coding rounds, pair this with Java Coding Programs for Interview; for CI/CD depth, The Complete Jenkins Tutorial.
From Real Projects
Across Apkope, Canolog and Testsigma I've done both manual testing and Selenium automation in Java with TestNG, tracked execution in TestRail and defects in Jira, and worked in Agile teams. The topics on this page connect directly to that day-to-day work. Work through the sections in order; each builds on the locators and waits covered before it.
Frequently Asked Questions
What is the best order to learn Selenium?
Fundamentals and locators, then waits and element interactions, then TestNG, the Page Object Model, Grid and CI, and finally interview preparation — practising each step as you go.
Do I need Java before learning Selenium?
Yes. Core Java — OOP, collections, loops, exception handling and file handling — is essential for writing and maintaining Selenium frameworks. See Java for Testers.
How long does it take to learn Selenium?
A few weeks to write reliable scripts comfortably, and around two to three months of consistent practice to build and explain a complete framework.
Is Selenium still worth learning?
Yes. It's a W3C standard, supported by every major browser vendor, and widely used in enterprise projects — and the concepts (locators, waits, page objects) transfer directly to Playwright and other tools.
Which Selenium framework should I build?
A hybrid framework using the Page Object Model with TestNG, data-driven support, reporting and CI integration — the most common setup in enterprise projects.
Do I still need to download ChromeDriver?
No. Since Selenium 4.6, Selenium Manager downloads the matching driver automatically.
How do I prepare for Selenium interviews?
Practise coding exercises and locators, solve scenario-based questions, understand your framework's architecture, and be able to explain your project end to end.