Selenium Tutorial
Learn Selenium step by step: 35 lessons in 10 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is Selenium? Learn what Selenium is: browser automation with WebDriver, the IDE and Grid, what it is used for, and how it compares with Playwright and Cypress.
- How WebDriver Works See how WebDriver works: your script, a driver program and the browser exchange JSON over HTTP using sessions and element ids defined by a W3C standard.
- Setup and Your First Script Install Selenium bindings for Python, Java or JavaScript, let Selenium Manager fetch the driver, then open a page, read its title and quit cleanly.
Finding Elements
- Locators: id, name, class and tag Find elements with Selenium's simplest locators: By.ID, NAME, CLASS_NAME and TAG_NAME. Learn find_element versus find_elements and NoSuchElementException.
- CSS Selector Locators Use CSS selectors as Selenium locators: ids, classes, attribute matches, combinators and structural pseudo-classes, and why CSS is the default choice.
- XPath Locators Learn XPath for Selenium: absolute and relative paths, predicates, text() and contains(), and axes to reach parents and siblings, with runnable examples.
- Choosing Stable Locators Pick Selenium locators that survive redesigns: test ids, ARIA attributes, link text, relative locators, and a ranking that tells you which strategy to try first.
Interacting with the Page
- Clicking and Typing Learn the everyday Selenium actions: click, send_keys, clear, special Keys, reading text and attributes, and checking is_displayed, is_enabled and is_selected.
- Forms, Checkboxes and Dropdowns Automate forms with Selenium: the Select class for dropdowns, checkbox and radio state, reading validation messages, and submitting a form safely.
- Mouse and Keyboard: the Actions API Use Selenium ActionChains for hover menus, drag and drop, double and right clicks, key chords and scrolling, and learn why perform() is always required.
- Alerts, Frames and Windows Learn how Selenium switches context: handling JavaScript alerts, working inside iframes, and moving between windows and tabs with window handles.
- File Uploads, Downloads and Screenshots Handle files in Selenium: upload with send_keys on file inputs, set a download directory and wait for the file, and take element and full-page screenshots.
Waiting and Synchronization
- Why Tests Need Waits Learn why a Selenium script races the page it controls, what NoSuchElement, StaleElementReference and ElementNotInteractable errors mean, and why sleep() is a poor fix.
- Implicit, Explicit and Fluent Waits Learn Selenium's three kinds of waits: implicit, explicit with WebDriverWait and expected conditions, and fluent waits with polling and ignored exceptions.
Test Structure
- The Page Object Model Learn the Page Object Model: one class per page, locators in one place, methods named after user actions, and returning the next page object to keep tests readable.
- Selenium with pytest Use pytest with Selenium: a driver fixture with setup and teardown, conftest.py, headless option, parametrized tests and markers, plus a runnable fixture stand-in.
- Selenium with JUnit and TestNG Structure Selenium tests in Java with JUnit 5 or TestNG: project layout, setup and teardown annotations, assertions, data-driven tests and suites, with a lifecycle stand-in.
- Test Data and Configuration Keep Selenium tests flexible: configuration files, environment URLs, credentials from environment variables, and data-driven tests fed from CSV and JSON files.
Selenium 4 Features
- What Is New in Selenium 4 A tour of Selenium 4: W3C WebDriver compliance, relative locators, new tab and window API, element screenshots, DevTools access and BiDi, plus migration tips.
- DevTools Protocol and BiDi Use Chrome DevTools Protocol commands and WebDriver BiDi events from Selenium: capture console logs, intercept network calls, emulate devices and geolocation.
Browsers and Scale
- Headless Mode and Browser Options Configure Chrome, Firefox and Edge in Selenium: headless mode, window size, proxies, profiles, page load strategy and the W3C capabilities behind options.
- Selenium Grid Understand Selenium Grid 4: standalone, hub and node modes, how capabilities choose a node, RemoteWebDriver, Docker images and running tests in parallel.
- Cloud Providers and Mobile with Appium Run Selenium tests on vendor clouds and test mobile apps with Appium: remote execution, W3C capabilities, vendor options, costs and when each choice makes sense.
Quality and Reliability
- Flaky Tests and Debugging Find and fix flaky Selenium tests: common causes, screenshots and logs on failure, video, why blind retries hide bugs, and how to isolate test state.
- Running in CI Run Selenium tests in CI: a GitHub Actions workflow, headless Chrome in containers, pytest-xdist and TestNG parallel runs, and uploading reports as artifacts.
- Reporting and Logging Make Selenium runs readable: pytest-html and Allure reports, structured JSON logs, and screenshots, page source and URLs saved automatically when a test fails.
- Security, Ethics and Scraping Limits Keep Selenium tests safe and responsible: handle secrets and test accounts, respect robots.txt and terms of service, throttle requests, and know when not to scrape.
Projects
- Project: Login Test Suite Build a login test suite step by step: valid and invalid credentials, error messages, lockout, a page object and data-driven cases, with a runnable stand-in app.
- Project: Shopping Cart Checkout Automate an end-to-end shopping flow: add items, verify totals, choose shipping from a dropdown, wait for an async checkout and assert the order confirmation.
- Project: Form Validation Checks Test form validation with Selenium: required fields, pattern rules, error summaries and accessibility attributes such as aria-invalid and aria-describedby.
- Project: Extracting Table Data Build a table extractor: read rows and cells, walk through pagination safely, clean the values and export CSV, with runnable pandas-free stand-ins.
- Project: A Small Test Framework Combine a config loader, driver factory, base page, reporting and screenshots on failure into one tidy Selenium test layout, with runnable stand-ins.
Practice and Review
- Practice Exercises with Solutions Five hands-on Selenium exercises on locators, waits, page objects, forms and exceptions, each with a hint, a runnable stand-in solution and a discussion.
- Selenium Interview Questions Prepare for Selenium interviews with concise answers on WebDriver architecture, locators, waits, exceptions, POM, Grid, flaky tests and Selenium vs Playwright.
- Selenium Cheat Sheet A one-page Selenium cheat sheet with Python and Java side by side: locators, element actions, waits, switching, exceptions, browser options and Grid.