lecture 3 of 200 completed

Installing Selenium and its drivers

Setup is harder here than in the other two tools. Here is what each piece is, and why the classic version mismatch no longer bites.

⚠️ Expect this to be harder than Cypress or Playwright.

Those tools download their own browsers and manage them. Selenium drives the browsers already on your machine, which means versions have to line up. This was the classic first-day frustration, and it is worth knowing why even though modern Selenium mostly solves it.

Install the library:

npm install selenium-webdriver --save-dev

That gives you the client library, the thing your test code imports. It is not enough on its own, and understanding why matters.

Three pieces have to agree.

  1. Your test code, using the selenium-webdriver library.
  2. A driver process, a small program that speaks WebDriver to one specific browser. ChromeDriver for Chrome, geckodriver for Firefox.
  3. The browser itself.

The driver has to match the browser's version. When Chrome updates itself overnight and your ChromeDriver does not, every test fails the next morning with a message about an unsupported version. Teams used to lose hours to this regularly.

Selenium Manager fixes it. Modern Selenium detects your browser and fetches the right driver automatically. You usually do nothing. If you read a tutorial that says to download ChromeDriver by hand and set a PATH variable, it predates this.

A first test file looks like this:

const { Builder, By, until } = require('selenium-webdriver');

async function run() {
  const driver = await new Builder().forBrowser('chrome').build();

  try {
    await driver.get('http://localhost:3000/login');
    await driver.findElement(By.css('[data-testid="email"]')).sendKeys('demo@nimbus.app');
    await driver.findElement(By.css('[data-testid="login"]')).click();
    await driver.wait(until.elementLocated(By.css('[data-testid="welcome"]')), 5000);
  } finally {
    await driver.quit();
  }
}

Two things to notice, because they shape everything in this track.

new Builder().forBrowser('chrome').build() starts a browser. You did that, explicitly. Cypress and Playwright hide this; Selenium does not.

try / finally with driver.quit(). If your test throws before quit runs, the browser stays open forever. Run a suite like that a few times and your machine fills with orphaned browser processes. There is a lecture on this later, and it is the most common Selenium beginner mistake after waiting.

Selenium does not come with a test runner. This surprises people. Cypress and Playwright each ship one. Selenium gives you browser control only, so you bring your own: Mocha or Jest in JavaScript, JUnit or TestNG in Java, pytest in Python. That is also why assertions come from a separate library, which has its own lecture.

Remember this: the library drives a driver that drives the browser, Selenium Manager keeps the versions aligned, and you supply the test runner.

Reference: Install a Selenium library.