Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 35 ยท 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.

Selenium is a free, open source set of tools for controlling a web browser with code. You write a script that says "open this page, type into that box, click this button, read what appears", and a real browser carries out those steps exactly as a person would. Because the browser is real, you test what users actually get: real rendering, real JavaScript, real forms.

People use Selenium for three main jobs: testing web applications automatically, repeating chores in a browser (filling the same form fifty times), and checking many browsers with the same script. This tutorial focuses on testing, which is where Selenium is strongest, and shows you how to write tests that stay reliable as your site grows.

The real Selenium needs a browser, a driver program and a language runtime, so it cannot run on this site. Selenium code in this tutorial is shown in read-only blocks. Every lesson also has runnable stand-ins: small models in plain JavaScript that behave like the real thing so you can see the ideas work. Each lesson says which part is real and which is the stand-in.

The three parts of the project

"Selenium" is a family, not one program.

One name, three tools

WebDriver A library and protocol that drive a browser from code.
Selenium IDE A browser extension that records and replays clicks.
Selenium Grid Runs your tests on many machines and browsers at once.

WebDriver is the core. Most of this tutorial is about it.

1 / 2

Selenium WebDriver is the part you will use every day. It is a set of language libraries (called bindings) plus a standard protocol for talking to browsers. You write ordinary Python, Java, C#, Ruby, JavaScript or Kotlin, and the library turns your calls into browser actions. The next lesson opens the box and shows what travels between your script and the browser.

Selenium IDE is a browser extension that records your clicks and typing and replays them later. It is handy for a first prototype or for people who do not write code, but recorded scripts are hard to maintain, so serious suites are written as code with WebDriver.

Selenium Grid lets you run many browser sessions in parallel, on several machines, with different browsers and operating systems. You will meet it in Selenium Grid once your suite grows.

A first look at the idea

Here is what a Selenium script looks like in Python. Do not run it yet, setup comes in a moment. Just read it.

Python
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()                 # start a real Chrome
driver.get("https://shop.example/login")    # open a page

driver.find_element(By.ID, "email").send_keys("[email protected]")
driver.find_element(By.ID, "password").send_keys("s3cret!")
driver.find_element(By.CSS_SELECTOR, "button[type=submit]").click()

print(driver.title)                         # what the browser shows now
driver.quit()                               # close the browser

The script has the same shape every Selenium test has: start a browser, navigate, find elements, act on them, check the result, quit. The rest of the tutorial is about doing each step well.

What it is used for

  • End-to-end tests. Walk through a whole user journey (sign up, add to cart, pay) and check that the final page is right.
  • Regression checks. Re-run the same flows after every change so a bug that was fixed stays fixed.
  • Cross-browser checks. Run one script against Chrome, Firefox, Edge and Safari.
  • Repetitive browser tasks. Fill in forms, download reports, take screenshots on a schedule.

It is not the right tool for everything. A test that checks a single calculation should be a fast unit test, not a browser test. Browser tests are slower and more fragile, so use them for the flows that truly need a browser. The idea of a healthy mix is covered in Testing Landscape.

Selenium IDE in practice

The IDE is a Chrome, Edge and Firefox extension that you install from the browser's extension store. After installing, open it from the toolbar, create a project, type the base URL of the site you want to test, and press the record button. Every click and keystroke becomes a row in the test editor: a command (such as open, click, type, assert text), a target (a locator) and a value. These commands are called Selenese, Selenium's own small scripting vocabulary.

The window has a toolbar with record, run-current-test, run-all-tests, pause and step-over buttons, plus a speed slider. You can set a breakpoint on any row so the run stops there, then step over one command at a time to see what the page looks like. A test suite groups tests, and control-flow commands (if, while, times) add basic logic. Finally, the IDE can export a recorded test as WebDriver code in several languages, which is the usual way to graduate from a prototype to a maintainable script; it also has a command-line runner so recorded suites can run in CI.

Limits to remember: recordings tend to pick brittle locators, there is little reuse (no page objects, no data-driven structure beyond simple tables), it cannot test REST or SOAP services, and large suites are hard to maintain. Treat the IDE as a learning aid and a prototyping tool.

Selenium RC and why WebDriver replaced it

Selenium RC (Remote Control) was the first server-based version of Selenium. Your test sent Selenese commands to the RC server, which injected a JavaScript program called Selenium Core into the page and ran the commands from inside the browser. This worked on any browser, but had real drawbacks: the injected JavaScript was bound by the browser's same-origin policy (so the server acted as an HTTP proxy), tests were slow because every command passed through the server and the JavaScript layer, the API was large and cluttered, and the text-oriented commands were less natural than an object-oriented API. WebDriver replaced it by talking to each browser through its own native driver, so there is no injected JavaScript, tests are faster and more realistic, and the API is cleaner. The two were merged as Selenium 2, and RC was deprecated and then removed in Selenium 4. Today you only meet RC in legacy suites. See how WebDriver works for the current architecture.

Limitations of Selenium

Knowing what Selenium cannot do saves time:

  • It automates web browsers only. Native desktop apps and native mobile apps need other tools (Appium builds on the WebDriver protocol for mobile).
  • There is no built-in reporting, test runner or test management. You pair it with JUnit, TestNG, pytest and a reporting library (see reporting and logging).
  • It cannot test REST or SOAP APIs directly; use an API tool or an HTTP client for that (see the API and database checks in the software testing track).
  • CAPTCHAs, one-time passwords and anti-bot protections cannot be automated by design; test environments should disable them.
  • It does not do image-based testing, pixel comparison or video and audio checks without extra tools.
  • It needs programming skill to write stable tests, and a suite needs steady maintenance because pages change. Slow, flaky tests are the usual result of weak waits and locators (see why tests need waits and flaky tests and debugging).
  • There is no vendor support line: help comes from documentation, open-source forums and the community.

A stand-in: scripting a fake page

The runnable code below is not Selenium. It is a tiny model of a page and a driver, written in plain JavaScript, so you can watch the same shape (navigate, find, act, check) without a browser. The fake driver has methods named like Selenium's.

JS A fake driver scripting a fake page

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The real Selenium has the same rhythm, but behind each method call there is a message to a real browser. Change the password in the example to see the FAIL path.

The same script on many browsers

One reason teams adopt Selenium is that a single script can run on several browsers. The model below runs one test function against three fake "browsers" and reports each result. Real cross-browser runs need real browsers (or a Grid), but the structure, one test and a list of targets, is the same.

JS One test, three browsers

Press Run (or Ctrl + Enter) to see the console output here.

No output.

This is the value of cross-browser automation in one picture: one browser disagrees, and you find out before your users do.

Selenium, Playwright and Cypress

Selenium is the oldest and most widely used browser automation tool, and it has two famous modern neighbors, Playwright and Cypress. All three drive a real browser. Their differences:

Selenium Playwright Cypress
Languages Java, Python, C#, Ruby, JavaScript, Kotlin JavaScript, TypeScript, Python, Java, .NET JavaScript, TypeScript
How it controls the browser Standard WebDriver protocol through a driver program Its own protocol, from a separate process Runs inside the browser
Waiting for elements You add waits yourself Built-in auto-waiting Built-in retrying
Strength Huge ecosystem, every major browser, many languages Modern API, fast, easy parallelism Friendly runner and debugging

Selenium's biggest advantages are its standard protocol (a W3C specification), its language choice, and the huge number of existing test suites, tools and cloud services built around it. Its main cost is that more things are your responsibility, especially waiting. For a side-by-side look at the other two, read Cypress vs Playwright. Knowing Selenium makes both easier to learn, because the underlying ideas (locators, waits, page objects) are the same.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which part of the Selenium project do you use to write test code in Python or Java?

    WebDriver provides the language bindings and the protocol used to drive a browser from code. The IDE records clicks, and Grid runs sessions in parallel.
  2. 2. What is Selenium Grid for?

    Grid routes browser sessions to different machines, so many tests can run in parallel on different browsers and operating systems.
  3. 3. Why shouldn't every test in a project be a Selenium browser test?

    Browser tests exercise the whole stack, so they take longer and break more easily. Use them for flows that need a real browser and keep fast unit tests for the rest.
  4. 4. In the fake-driver example, what is the stand-in for?

    The real Selenium needs a browser and a driver program, so the site uses a small model with Selenium-style method names to show the idea.

Summary

  • Selenium is a set of tools for controlling real browsers from code: WebDriver (the core), IDE (record and replay) and Grid (parallel and remote runs).
  • A script follows one shape: start a browser, navigate, find elements, act, check, quit.
  • Typical uses are end-to-end tests, regression checks, cross-browser checks and repetitive browser tasks.
  • Browser tests are slow compared with unit tests, so use them where a real browser is needed.
  • Compared with Playwright and Cypress, Selenium offers more languages and a standard protocol, and leaves waiting to you.

Next, look inside the protocol in How WebDriver Works.