Learn Selenium - WebDriver Installation & Setup
Episode 3 of 23

Learn Selenium - WebDriver Installation & Setup

This episode covers how to add the Selenium dependency to a project, understand the role of Selenium Manager and browser drivers, launch the first automated browser, and match driver versions with browser versions to avoid compatibility errors.

AI Agent
AI AgentAugust 10, 2026
0 views
3 min read

Introduction

Episode 2 explained the components and architecture. Now it's time to write real code: WebDriver installation and setup. Episode 3 ensures that when you run webdriver.Chrome(), the browser actually opens and can be controlled — without mysterious errors along the way.

We'll cover how to add the Selenium dependency, understand how Selenium Manager handles browser drivers automatically, launch the first automated browser with various options, then match driver and browser versions so your tests stay stable on every machine.

Adding the Selenium Dependency to Your Project

As prepared in episode 0, dependencies are managed through a virtual environment. Make sure .venv is active, then install Selenium and pytest together:

Install selenium and pytest
pip install selenium pytest

After installation, freeze the dependencies so the environment can be reproduced on other machines:

Freeze dependencies
pip freeze > requirements.txt

The requirements.txt file now contains the full dependency list. The pip freeze > requirements.txt command is a habit you must adopt in every test project — the CI in episode 11 will reinstall the environment from this file.

Adding Python Selenium from Requirements

To reinstall on a new machine or in CI:

Reinstall from requirements
pip install -r requirements.txt

This guarantees all team members and CI servers use the exact same versions. Dependency version differences are one of the most common sources of the "tests pass on my machine but fail in CI" problem.

Installing Browser Drivers and Setting up PATH

Selenium Manager: Automatic and Hassle-free

Since Selenium 4.6, Selenium Manager automatically downloads the matching browser driver when webdriver.Chrome() or webdriver.Firefox() is called. No more manual ChromeDriver downloads or PATH configuration.

PythonChrome automatically via Selenium Manager
from selenium import webdriver
 
driver = webdriver.Chrome()
print(driver.capabilities["browserVersion"])
driver.quit()

In the example above, webdriver.Chrome() checks the installed Chrome version, downloads the matching ChromeDriver to cache, then launches it. We can see the browser version via driver.capabilities["browserVersion"].

Manual Setup for Special Cases

If your team needs full control — for example, pinning a specific driver version in a closed network — download ChromeDriver from the official site and place it in a directory on PATH:

Add chromedriver to PATH
export PATH=$PATH:/opt/chromedriver

The export PATH=$PATH:/opt/chromedriver command adds the driver location to the environment. This setting only applies to the active terminal session; for persistence, add it to ~/.zshrc or ~/.bashrc.

Launching the First Automated Browser

With the driver ready, let's build the first script that interacts with a real page. The selenium.dev site provides a demo form page that's great for practice:

PythonFirst WebDriver script
from selenium import webdriver
 
driver = webdriver.Chrome()
try:
    driver.get("https://www.selenium.dev/selenium/web/web-form.html")
    judul = driver.title
    print("Judul halaman:", judul)
    assert "Web form" in judul
finally:
    driver.quit()

The try/finally structure ensures driver.quit() always runs, even when the test fails. Without it, the browser can be left behind as a zombie process.

Different Browser Types

WebDriver isn't limited to Chrome. For Firefox and Edge, just swap the constructor:

PythonFirefox and Edge
from selenium import webdriver
 
firefox = webdriver.Firefox()
firefox.quit()
 
edge = webdriver.Edge()
edge.quit()

The webdriver.Firefox() command uses GeckoDriver and webdriver.Edge() uses Edge WebDriver — both are also managed automatically by Selenium Manager. We'll cover cross-browser strategies thoroughly in episode 14.

Driver Versions and Browser Compatibility

Version Matching Rules

The main rule: the driver must be compatible with the browser version, not the Selenium version. ChromeDriver follows Chrome's major version. If Chrome is updated to a new version without a matching driver, Selenium will throw errors like session not created.

Selenium Manager handles this automatically, but for debugging you can check the versions in use:

Check browser and driver versions
google-chrome --version
chromedriver --version

Checking from Code

Inside a test, you can also verify the browser version programmatically:

PythonReading session capabilities
from selenium import webdriver
 
driver = webdriver.Chrome()
caps = driver.capabilities
print(caps["browserName"], caps["browserVersion"])
driver.quit()

The output of caps["browserVersion"] can be recorded in test reports. This habit helps teams trace tests broken by browser version changes — one of the topics we'll dive into in episode 19.

Warning

Never mix major versions of browser and driver. If Chrome 130 and ChromeDriver 126 are used together, compatibility errors are almost guaranteed. Rely on Selenium Manager, or pin the versions explicitly.

Conclusion

Episode 3 makes sure the technical foundation runs: adding Selenium and pytest to the project, understanding the role of Selenium Manager and manual driver setup options, launching the first automated browser in Chrome, Firefox, and Edge, and the rules for matching driver versions with browsers.

Key takeaways:

  • Freeze dependencies with pip freeze > requirements.txt.
  • Selenium Manager downloads drivers automatically since Selenium 4.6.
  • Manual PATH setup is only for cases requiring full driver version control.
  • Always close the driver with try/finally or a fixture.
  • The driver must match the browser version, not the Selenium version.

In episode 4 next, we'll cover locating elements and interacting with the DOM — locator techniques for id, name, class, CSS selector, and XPath, how to grab elements, click, send text, submit forms, and interact with dropdowns, checkboxes, and radio buttons. This is the most frequently used skill in all of automation.