Hero Background

Next-Gen App & Browser Testing Cloud

Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Next-Gen App & Browser Testing Cloud

How do I install Selenium and set up the environment for testing?

To install Selenium and set up a testing environment, install a language runtime (such as the JDK for Java or Python 3), add the Selenium client library through a build tool like Maven or pip, choose an IDE, and let Selenium Manager handle browser drivers automatically. You are then ready to write and run your first test. Modern Selenium removes most of the manual driver setup that older guides describe.

This guide walks through the full setup for both Java and Python, shows a working first script, explains the mistakes beginners hit most often, and covers how to skip local driver management entirely by running on a cloud grid. If you want a broader reference afterwards, the Selenium WebDriver tutorial and the WebDriver learning hub go deeper.

Prerequisites Before You Start

Regardless of language, a Selenium environment needs a few basic pieces in place:

  • A language runtime: The JDK for Java, or Python 3 for Python.
  • A build or package manager: Maven or Gradle for Java, pip for Python, to pull in the Selenium client library.
  • An IDE or editor: IntelliJ IDEA or Eclipse for Java; VS Code or PyCharm for Python.
  • A browser: Chrome, Firefox, or Edge installed locally if you plan to run tests on your own machine.

Install Selenium with Java and Maven

For Java, install the latest JDK from an OpenJDK or Oracle distribution and set the JAVA_HOME environment variable. Then create a Maven project and add the Selenium dependency to your pom.xml so the build tool manages the library and its versions for you:

<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>4.25.0</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>7.10.2</version>
        <scope>test</scope>
    </dependency>
</dependencies>

Run mvn clean install to download the dependencies. With Selenium 4.6 and later, you do not need to download ChromeDriver or GeckoDriver manually, Selenium Manager resolves the correct driver at runtime.

Install Selenium with Python

Python setup is even shorter. Install Python 3, then use pip to add Selenium. Using a virtual environment keeps dependencies isolated per project:

# Create and activate a virtual environment (optional but recommended)
python -m venv venv
source venv/bin/activate        # Windows: venv\Scripts\activate

# Install the Selenium package
pip install selenium

# Confirm the installed version
python -c "import selenium; print(selenium.__version__)"

That single pip command installs Selenium and its dependencies. As with Java, driver management is automatic in modern versions.

Write and Run Your First Test

With the library installed, a minimal test confirms the environment works end to end. This Java example opens a page, reads its title, and closes the browser:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class FirstTest {
    public static void main(String[] args) {
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.google.com");
        System.out.println("Page title: " + driver.getTitle());
        driver.quit();
    }
}

If the browser launches and prints the title, your installation is correct. From here you can add a framework such as TestNG or pytest to structure and report on your tests. For the next step, see how to write and run test scripts in Selenium.

Common Mistakes and Troubleshooting

  • Driver and browser version mismatch: The classic cause of SessionNotCreatedException. Upgrade to Selenium 4.6+ so Selenium Manager handles versions.
  • JAVA_HOME not set: Maven and the JDK fail silently if environment variables are missing. Verify with java -version and mvn -version.
  • Manually managing drivers unnecessarily: Old tutorials tell you to download drivers by hand; on modern Selenium this only causes conflicts.
  • Installing into the global Python environment: Skipping a virtual environment leads to dependency clashes between projects.
  • Forgetting driver.quit(): Orphaned browser processes pile up and slow the machine over long runs.

Run Selenium Across Real Browsers and Devices

Local setup is fine for writing tests, but it limits you to the browsers on your own machine and adds driver maintenance. By pointing your WebDriver at a cloud grid, you skip local drivers entirely and gain far broader coverage. TestMu AI lets you run Selenium tests across 3000+ real browsers and devices without installing any of them locally, so you can validate Chrome, Safari, Edge, and mobile combinations from one script. It is the fastest way to move from a working local setup to reliable cross browser testing and full automation testing at scale.

Conclusion

Setting up Selenium is far simpler than older guides suggest: install a runtime, pull the client library with Maven or pip, pick an IDE, and let Selenium Manager handle drivers. A quick first script confirms everything works. When you are ready to test beyond your local machine, a real-device cloud removes driver upkeep and unlocks thousands of browser and OS combinations, turning a basic install into a production-grade testing environment.

Frequently Asked Questions

Do I need to install browser drivers separately for Selenium?

Not anymore in most cases. Selenium 4.6 and later include Selenium Manager, which automatically downloads and configures the correct driver for your installed browser. You only need to manage drivers manually for older Selenium versions or unusual setups.

Which language should I use with Selenium?

Selenium supports Java, Python, C#, JavaScript, and Ruby. Java and Python are the most common: Java pairs well with Maven and TestNG for large teams, while Python is quicker to start with thanks to pip and concise syntax. Choose the language your team already knows.

How do I install Selenium in Python?

Install Python 3, then run pip install selenium in your terminal. This pulls the latest Selenium package and its dependencies. With Selenium Manager handling drivers, you can immediately instantiate a WebDriver and write your first test without extra configuration.

What is the difference between Selenium Manager and manual driver setup?

Selenium Manager automatically resolves, downloads, and caches the browser driver that matches your browser version at runtime. Manual setup requires you to download the driver, match its version to the browser, and add it to the system PATH, which is more error-prone.

Can I run Selenium tests without installing browsers locally?

Yes. A cloud grid like TestMu AI (Formerly LambdaTest) hosts thousands of real browser and OS combinations, so you point your WebDriver at the remote endpoint instead of a local browser. This removes local driver and browser maintenance and lets you test environments you do not have on your machine.

Why do I get a SessionNotCreatedException?

A SessionNotCreatedException usually means the driver and browser versions are incompatible. Update both to compatible versions, or upgrade to Selenium 4.6+ so Selenium Manager resolves the correct driver automatically. Also confirm the browser is actually installed on the machine running the test.

Related Questions

Test Your Website on 3000+ Browsers

Get 100 minutes of automation test minutes FREE!!

Test Now...

KaneAI - Testing Assistant

World’s first AI-Native E2E testing agent.

...

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests