Popular Searches
Popular Course Categories
Popular Courses

Installing Selenium

Selenium Environment Setup

Installing Selenium

Selenium is an open-source automation framework used to automate web browsers and test web applications. It allows developers and testers to write automation scripts that can open browsers, navigate to websites, locate web elements, enter data, click buttons, validate results, handle browser windows, work with alerts, and perform many other browser-based operations.

Installing Selenium is the first major step in creating a Selenium automation environment. A proper Selenium setup requires a programming language, Selenium libraries, a suitable development environment or IDE, a supported web browser, and the required browser automation components.


1. What is Selenium?

Selenium is a collection of tools and libraries designed for automating web browsers. It is primarily used for functional testing, regression testing, cross-browser testing, UI testing, and web application automation.

Selenium supports popular programming languages such as Java, Python, C#, JavaScript, and Ruby. The Selenium WebDriver API allows automation scripts to communicate with supported browsers.

Common Selenium Uses

  • Web application automation
  • Functional testing
  • Regression testing
  • Smoke testing
  • Cross-browser testing
  • UI testing
  • End-to-end testing
  • Data-driven testing
  • Automated browser interaction
  • Continuous integration testing


2. Selenium Installation Requirements

Before installing Selenium, the automation environment should have the required software and tools.

RequirementPurpose
Operating SystemProvides the environment for running automation tools.
Programming LanguageUsed to write Selenium automation scripts.
IDE or Code EditorUsed to create, edit, execute, and debug automation code.
Selenium LibraryProvides Selenium APIs for browser automation.
Web BrowserThe browser that will be automated.
Browser Automation SupportAllows Selenium to communicate with the selected browser.
Package ManagerUsed to install and manage Selenium dependencies.


3. Selenium Installation Flow

Operating System

       ↓

Programming Language

       ↓

IDE / Code Editor

       ↓

Package Manager

       ↓

Selenium Library

       ↓

Browser Automation Support

       ↓

Web Browser

       ↓

Selenium Automation Script

The exact installation process depends on the programming language being used. Java commonly uses Maven or Gradle, while Python commonly uses pip and virtual environments.


4. Supported Programming Languages

Selenium provides bindings for several programming languages.

LanguageCommon ToolsTypical Package Management
JavaIntelliJ IDEA, EclipseMaven / Gradle
PythonPyCharm, VS Codepip / virtual environment
C#Visual StudioNuGet
JavaScriptVS Codenpm
RubyVS Code / Ruby IDEsRubyGems


5. Installing Selenium with Python

Python is one of the commonly used languages for Selenium automation. Selenium can be installed using Python's package manager, pip.

Step 1: Check Python Installation

Open Command Prompt, PowerShell, Terminal, or the integrated terminal of your IDE and execute:

python --version

On some systems, the following command may be required:

python3 --version

If Python is installed correctly, the terminal displays the installed Python version.

Step 2: Check pip

python -m pip --version

The command verifies that pip is available for the selected Python installation.

Step 3: Install Selenium

python -m pip install selenium

This command downloads and installs the Selenium Python package and its required dependencies.

Step 4: Verify Selenium Installation

python -m pip show selenium

You can also verify the installed Selenium version with:

python -c "import selenium; print(selenium.__version__)"


6. Installing Selenium in a Python Virtual Environment

A virtual environment provides an isolated Python environment for a project. It helps prevent dependency conflicts between different automation projects.

Create Virtual Environment

python -m venv venv

Activate on Windows

venv\Scripts\activate

Activate on macOS/Linux

source venv/bin/activate

Install Selenium

python -m pip install selenium

Deactivate Environment

deactivate

Using a virtual environment is especially useful when multiple Selenium projects require different package versions.


7. Creating requirements.txt

Python Selenium projects can store their dependencies in a requirements.txt file.

python -m pip freeze > requirements.txt

Another developer can install the project dependencies with:

python -m pip install -r requirements.txt

This makes it easier to recreate the same Python environment on another computer.


8. Installing Selenium with Java

Java Selenium projects commonly use Maven or Gradle to manage Selenium dependencies.

Check Java

java --version

Also verify the Java compiler:

javac --version

If these commands are not recognized, install and configure an appropriate JDK before creating the Selenium project.


9. Creating a Java Selenium Project with Maven

Maven is commonly used to manage dependencies in Java Selenium projects. A Maven project contains a pom.xml file that defines project dependencies and build configuration.

Basic Selenium Dependency

   

        org.seleniumhq.selenium

        selenium-java

        YOUR_VERSION

   

Replace YOUR_VERSION with the Selenium version selected for the project.

Maven Installation Flow

pom.xml

   ↓

Maven

   ↓

Selenium Dependency

   ↓

Project Libraries

   ↓

Java Selenium Code

   ↓

Browser Automation


10. What is Maven?

Maven is a build automation and dependency management tool commonly used for Java projects.

Maven Responsibilities

  • Managing project dependencies
  • Downloading required libraries
  • Managing plugins
  • Compiling source code
  • Running tests
  • Creating project builds
  • Managing project configuration

Check Maven Installation

mvn --version


11. Installing Selenium Using an IDE

An IDE makes Selenium development easier by providing code completion, syntax highlighting, debugging, project management, dependency management, integrated terminals, and test execution.

Popular IDEs

  • IntelliJ IDEA for Java
  • Eclipse for Java
  • PyCharm for Python
  • Visual Studio Code for Python, Java, JavaScript, and other languages
  • Visual Studio for C#


12. Selenium Installation Using IntelliJ IDEA

For Java Selenium automation, IntelliJ IDEA can be used as the development environment.

Basic Steps

  1. Install the JDK.
  2. Install IntelliJ IDEA.
  3. Create a new Java project.
  4. Select the appropriate JDK.
  5. Create a Maven project if Maven is being used.
  6. Add the Selenium dependency to pom.xml.
  7. Allow Maven to download dependencies.
  8. Create a Selenium test class.
  9. Run the automation script.


13. Selenium Installation Using Eclipse

Eclipse is another commonly used Java IDE for Selenium automation.

Basic Steps

  1. Install the JDK.
  2. Install Eclipse.
  3. Open Eclipse.
  4. Create a Java project or Maven project.
  5. Configure the JDK.
  6. Add the Selenium dependency.
  7. Wait for Maven to download dependencies.
  8. Create a Selenium automation class.
  9. Execute the program.


14. Selenium Installation Using PyCharm

PyCharm is commonly used for Python-based Selenium automation.

Steps

  1. Install Python.
  2. Install PyCharm.
  3. Create a new Python project.
  4. Select the appropriate Python interpreter.
  5. Create or select a virtual environment.
  6. Open the terminal.
  7. Install Selenium using pip.
  8. Create a Python automation script.
  9. Run the script.

python -m pip install selenium


15. Selenium Installation Using Visual Studio Code

Visual Studio Code can be used for Selenium automation with Python, Java, JavaScript, and other supported languages.

Recommended Extensions

  • Python extension
  • Extension Pack for Java
  • Debugger extensions
  • Test-related extensions
  • Git-related extensions

After installing the required programming language extension, create a project folder and install the Selenium dependency using the appropriate package manager.


16. Installing Selenium WebDriver

Selenium WebDriver is the primary Selenium API used for browser automation. It allows automation code to interact with browsers programmatically.

Modern Selenium versions can use Selenium Manager to assist with browser driver management in supported configurations. This reduces the need for manually downloading and configuring browser driver executables in many common setups.

Automation Flow

Selenium Script

      ↓

WebDriver API

      ↓

Selenium Manager / Browser Driver

      ↓

Web Browser

      ↓

Web Application


17. Installing a Web Browser

Selenium requires a supported browser to execute browser automation. Common browsers used in Selenium testing include:

  • Google Chrome
  • Mozilla Firefox
  • Microsoft Edge
  • Safari on supported environments

The browser should be installed and available on the system before executing browser automation tests.


18. First Selenium Program in Python

After Selenium is installed, create a simple Python program to verify the installation.

from selenium import webdriver

 

driver = webdriver.Chrome()

 

driver.get("https://www.google.com")

 

print(driver.title)

 

driver.quit()

Program Explanation

  • webdriver provides Selenium browser automation functionality.
  • webdriver.Chrome() creates a Chrome browser session.
  • driver.get() navigates to the specified URL.
  • driver.title retrieves the current page title.
  • driver.quit() closes the browser session.


19. First Selenium Program in Java

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

 

public class FirstSeleniumTest {

 

    public static void main(String[] args) {

 

        WebDriver driver = new ChromeDriver();

 

        driver.get("https://www.google.com");

 

        System.out.println(driver.getTitle());

 

        driver.quit();

    }

}

Program Flow

Start Program

     ↓

Create ChromeDriver

     ↓

Open Chrome

     ↓

Navigate to Google

     ↓

Read Page Title

     ↓

Print Title

     ↓

Quit Browser


20. Verifying Selenium Installation

A successful Selenium installation should allow the automation program to import Selenium classes or modules and create a browser session.

Python Verification

python -m pip show selenium

python -c "import selenium; print(selenium.__version__)"

Java Verification

For Java, verify that the Selenium dependency is visible in the Maven project and that Selenium imports are resolved by the IDE.

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;


21. Selenium Installation Architecture

                 Selenium Automation

                         |

              +----------+----------+

              |                     |

          Python/Java            Other Languages

              |                     |

          Selenium API          Selenium Bindings

              |

           WebDriver

              |

     Selenium Manager / Driver

              |

           Browser

              |

       Web Application


22. Selenium Package Management

LanguagePackage ManagerExample
Pythonpippython -m pip install selenium
JavaMavenselenium-java dependency
JavaGradleSelenium dependency in build.gradle
C#NuGetSelenium WebDriver package
JavaScriptnpmSelenium WebDriver package


23. Installing Selenium with Gradle

Gradle is another build and dependency management tool that can be used with Java Selenium projects.

A Selenium dependency can be added to a Gradle project according to the project's dependency configuration.

dependencies {

    testImplementation "org.seleniumhq.selenium:selenium-java:YOUR_VERSION"

}

The exact version should be selected according to the project's requirements.


24. Selenium Installation Project Structure

SeleniumProject

|

+-- src

|   |

|   +-- test

|       |

|       +-- java

|           |

|           +-- tests

|           |   |

|           |   +-- LoginTest.java

|           |   +-- SearchTest.java

|           |

|           +-- pages

|           |   |

|           |   +-- LoginPage.java

|           |   +-- HomePage.java

|           |

|           +-- utils

|               |

|               +-- DriverFactory.java

|

+-- pom.xml

|

+-- testng.xml

|

+-- README.md

A project may use a different structure depending on the framework, language, build tool, and automation architecture.


25. Installing Selenium Test Frameworks

After installing Selenium, a test framework can be added to organize and execute automated tests.

Common Java Test Frameworks

  • TestNG
  • JUnit

TestNG Example

import org.testng.annotations.Test;

 

public class LoginTest {

 

    @Test

    public void loginTest() {

        System.out.println("Login test executed");

    }

}

JUnit Example

import org.junit.jupiter.api.Test;

 

public class SearchTest {

 

    @Test

    void searchTest() {

        System.out.println("Search test executed");

    }

}


26. Installing Selenium with TestNG

For a Maven-based Java project, TestNG can be added as a project dependency according to the selected TestNG version.

Once configured, TestNG can be used for:

  • Test annotations
  • Assertions
  • Test suites
  • Groups
  • Parameters
  • Data providers
  • Parallel execution
  • Test reporting


27. Selenium Installation with Page Object Model

Once Selenium is installed, larger projects can be organized using the Page Object Model (POM). In this design, web pages are represented as separate classes containing locators and page actions.

Example

public class LoginPage {

 

    private WebDriver driver;

 

    public LoginPage(WebDriver driver) {

        this.driver = driver;

    }

 

    public void enterUsername(String username) {

        // Enter username

    }

 

    public void enterPassword(String password) {

        // Enter password

    }

 

    public void clickLogin() {

        // Click login button

    }

}

POM can make automation projects easier to maintain and reuse.


28. Common Selenium Installation Errors

ErrorPossible CauseSolution
python is not recognizedPython is not installed or PATH is not configured.Install/configure Python and verify the PATH.
pip is not recognizedpip is unavailable in the selected Python environment.Use python -m pip or configure the Python environment.
ModuleNotFoundError: seleniumSelenium is not installed in the selected Python environment.Run python -m pip install selenium.
Java not recognizedJDK is missing or environment variables are not configured.Install/configure the JDK.
Cannot resolve Selenium importsSelenium dependency is missing from the Java project.Configure Maven/Gradle dependency and refresh the project.
Browser does not startBrowser or browser automation configuration problem.Verify browser installation and Selenium configuration.
Maven dependency errorIncorrect dependency or repository/configuration issue.Check pom.xml and refresh Maven.


29. Python Selenium Import Error

A common error is:

ModuleNotFoundError: No module named 'selenium'

This generally means Selenium is not installed in the Python environment being used to execute the script.

Solution

python -m pip install selenium

Then verify:

python -m pip show selenium

It is important to install Selenium into the same Python environment selected by the IDE.


30. Java Selenium Dependency Error

If the IDE cannot resolve Selenium classes such as WebDriver or ChromeDriver, check the project's dependency configuration.

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

For Maven projects, check the Selenium dependency in pom.xml and refresh the Maven project.


31. Refreshing Maven Dependencies

If Selenium dependencies are not recognized by the IDE, refresh or reload the Maven project.

You can also execute:

mvn clean install

This allows Maven to process the project configuration and dependencies.


32. Checking Browser Automation

After Selenium installation, execute a simple browser test.

from selenium import webdriver

 

driver = webdriver.Chrome()

 

driver.get("https://www.google.com")

 

print("Title:", driver.title)

 

driver.quit()

If the browser starts, navigates to the requested website, prints the title, and closes successfully, the basic Selenium environment is functioning.


33. Selenium Installation Best Practices

  • Use an appropriate and supported programming language version.
  • Keep Selenium dependencies managed by the project's package manager.
  • Use a Python virtual environment for Python projects.
  • Use Maven or Gradle for Java dependency management.
  • Keep browsers updated according to project requirements.
  • Use a dedicated automation project.
  • Keep dependencies documented.
  • Use meaningful project and test names.
  • Use Git for source-code version control.
  • Avoid unnecessary manual driver configuration when supported Selenium Manager functionality can handle the setup.
  • Verify the environment before starting large automation projects.


34. Common Mistakes During Selenium Installation

  1. Installing Selenium without installing the programming language.
  2. Using the wrong Python interpreter in the IDE.
  3. Installing Selenium globally when project isolation is required.
  4. Forgetting to configure the JDK for Java projects.
  5. Adding incorrect Selenium dependency versions.
  6. Ignoring Maven or pip installation errors.
  7. Using an unsupported or incorrectly configured browser environment.
  8. Not refreshing the IDE after adding dependencies.
  9. Running the script from a different Python environment.
  10. Not verifying the installation with a simple browser test.


35. Complete Python Selenium Installation Example

# Check Python

python --version

 

# Check pip

python -m pip --version

 

# Create virtual environment

python -m venv venv

 

# Activate environment on Windows

venv\Scripts\activate

 

# Install Selenium

python -m pip install selenium

 

# Verify Selenium

python -m pip show selenium

 

# Check Selenium version

python -c "import selenium; print(selenium.__version__)"


36. Complete Java Selenium Installation Flow

Install JDK

     ↓

Verify Java

     ↓

Install IntelliJ IDEA / Eclipse

     ↓

Create Maven Project

     ↓

Configure pom.xml

     ↓

Add Selenium Dependency

     ↓

Refresh Maven

     ↓

Create Selenium Class

     ↓

Create WebDriver

     ↓

Launch Browser

     ↓

Run Automation Test


37. Python Selenium Installation Flow

Install Python

     ↓

Verify Python

     ↓

Create Virtual Environment

     ↓

Activate Environment

     ↓

Install Selenium

     ↓

Verify Selenium

     ↓

Create Python Script

     ↓

Create WebDriver

     ↓

Launch Browser

     ↓

Execute Automation


38. Selenium Installation Verification Checklist

CheckVerification
Pythonpython --version
pippython -m pip --version
Selenium Python Packagepython -m pip show selenium
Javajava --version
Java Compilerjavac --version
Mavenmvn --version
Selenium Java DependencyCheck pom.xml and IDE dependency resolution
BrowserVerify the selected browser is installed
WebDriverExecute a basic browser automation script


39. Practical Selenium Installation Project

A simple Selenium installation project can be used to verify the complete environment.

Python Project

selenium-project/

|

+-- venv/

|

+-- test_browser.py

|

+-- requirements.txt

Python Script

from selenium import webdriver

 

driver = webdriver.Chrome()

 

driver.get("https://www.google.com")

 

print("Browser Title:", driver.title)

print("Current URL:", driver.current_url)

 

driver.quit()

Expected Flow

Run Script

    ↓

Create Chrome Session

    ↓

Open Google

    ↓

Read Title

    ↓

Read Current URL

    ↓

Close Browser

    ↓

Program Ends


40. Installing Selenium for a Real Automation Project

In a real automation project, Selenium installation is only the initial setup. After installation, the project can be expanded with page objects, test classes, test data, utilities, configuration files, reporting, logging, screenshots, and continuous integration.

Automation Project

|

+-- Selenium

|

+-- WebDriver

|

+-- Test Framework

|

+-- Page Objects

|

+-- Test Data

|

+-- Utilities

|

+-- Configuration

|

+-- Reports

|

+-- Logs

|

+-- Screenshots

|

+-- Git

|

+-- CI/CD


41. Selenium Installation and Git

After creating a Selenium project, Git can be used to maintain the source code and collaborate with other team members.

git init

git status

git add .

git commit -m "Add Selenium automation project"

git push

Dependency files such as pom.xml or requirements.txt should generally be included in the project so that the environment can be recreated.


42. Selenium Installation and CI/CD

Once Selenium is installed and the automation project is properly configured, automated tests can be integrated into CI/CD systems.

Developer

    ↓

Git Repository

    ↓

CI/CD Pipeline

    ↓

Install Dependencies

    ↓

Run Selenium Tests

    ↓

Generate Results

    ↓

Reports

A reproducible dependency configuration is important for CI/CD because the automation environment may need to be created automatically on a build server.


43. Selenium Installation Troubleshooting Guide

ProblemWhat to Check
Python command failsPython installation and PATH.
Selenium import failsSelected Python interpreter and Selenium installation.
Java command failsJDK installation and environment configuration.
Maven command failsMaven installation and PATH.
Selenium imports unresolvedMaven/Gradle dependency and project refresh.
Browser fails to launchBrowser installation and Selenium browser configuration.
IDE cannot find packageInterpreter, SDK, dependency, or project configuration.
Tests do not executeTest framework, test configuration, and project structure.


44. Learning Outcomes

After completing the Selenium installation setup, you should be able to:

  • Understand what Selenium is.
  • Understand Selenium installation requirements.
  • Choose a suitable programming language.
  • Install and verify Python for Selenium.
  • Install Selenium using pip.
  • Create and use a Python virtual environment.
  • Install and verify Java for Selenium.
  • Create a Maven Selenium project.
  • Add Selenium dependencies to Java projects.
  • Use an IDE for Selenium development.
  • Understand Selenium WebDriver.
  • Run a basic Selenium browser automation script.
  • Troubleshoot common installation problems.
  • Organize a Selenium automation project.
  • Prepare a Selenium project for further automation development.


45. Interview Questions

Q1. What is Selenium?

Selenium is an open-source framework and collection of tools used to automate web browsers and test web applications.

Q2. What is required before installing Selenium?

A suitable programming language environment, IDE or code editor, Selenium library, supported browser, and required dependency-management tools should be prepared.

Q3. How do you install Selenium in Python?

python -m pip install selenium

Q4. How do you verify Selenium in Python?

python -m pip show selenium

Q5. How do you check the Selenium version in Python?

python -c "import selenium; print(selenium.__version__)"

Q6. What is Maven used for in Selenium Java projects?

Maven is commonly used to manage Java project dependencies, plugins, builds, and test execution.

Q7. What is pom.xml?

pom.xml is the Maven project configuration file that contains project information, dependencies, plugins, and other build configuration.

Q8. What is a virtual environment?

A virtual environment is an isolated Python environment used to keep project dependencies separate from other Python projects.

Q9. What is WebDriver?

WebDriver is the Selenium API used by automation scripts to control supported web browsers.

Q10. Can Selenium be used without an IDE?

Yes. Selenium scripts can be created and executed from command-line environments, but an IDE provides additional development features such as code completion, debugging, project management, and integrated tooling.

Q11. What should you verify if Selenium cannot be imported?

Verify that Selenium is installed in the environment used to execute the script and that the IDE is using the correct interpreter or project configuration.

Q12. Why is dependency management important?

Dependency management helps projects install, maintain, document, and reproduce the libraries required for automation.


46. Quick Revision Checklist

  • Understand Selenium.
  • Install the programming language.
  • Verify the programming language.
  • Install an IDE.
  • Create the Selenium project.
  • Configure dependencies.
  • Install Selenium.
  • Configure a browser.
  • Create WebDriver.
  • Run the first Selenium script.
  • Verify browser automation.
  • Use virtual environments for Python projects.
  • Use Maven/Gradle for Java projects.
  • Organize automation files.
  • Use Git for source-code management.
  • Troubleshoot installation errors.


47. Recommended Selenium Learning Path

  1. Introduction to Selenium
  2. Installing Selenium
  3. IDE Setup
  4. Selenium WebDriver
  5. Locators
  6. WebElements
  7. Browser Commands
  8. Waits
  9. Alerts
  10. Frames
  11. Windows and Tabs
  12. Dropdowns
  13. Mouse and Keyboard Actions
  14. JavaScript Execution
  15. TestNG / JUnit
  16. Page Object Model
  17. Data-Driven Testing
  18. Automation Framework Development
  19. Git and GitHub
  20. CI/CD Integration
  21. Real-Time Selenium Automation Project


48. Selenium Training Resource

For structured Selenium automation testing training, practical projects, WebDriver concepts, automation frameworks, and interview preparation, you can explore the JustAcademy Selenium Training Course.

You can also use the JustAcademy Selenium Course Demo Registration link to register for a course demo.


49. Final Summary

Installing Selenium is the foundation of a web automation testing environment. The installation process depends on the programming language and development tools being used.

For Python, Selenium can be installed with pip and managed through a virtual environment. For Java, Selenium can be managed through Maven or Gradle. An IDE such as IntelliJ IDEA, Eclipse, PyCharm, or Visual Studio Code can make development, debugging, dependency management, and test execution easier.

After installation, the environment should be verified by executing a simple Selenium script that creates a browser session, navigates to a website, performs a basic operation, and closes the browser.

50. Complete Selenium Installation Workflow

Choose Programming Language

          ↓

Install Python / JDK

          ↓

Verify Installation

          ↓

Install IDE

          ↓

Create Project

          ↓

Configure Environment

          ↓

Install Selenium

          ↓

Configure Dependencies

          ↓

Install / Verify Browser

          ↓

Create WebDriver

          ↓

Run First Selenium Script

          ↓

Verify Browser Automation

          ↓

Add Test Framework

          ↓

Create Page Objects

          ↓

Build Automation Framework

          ↓

Run Tests

          ↓

Generate Reports

          ↓

Integrate Git & CI/CD

whatsapp