Selenium Installation and Setup

Complete notes for Selenium 4.6+ and above, including Java JDK, Eclipse, Maven, Selenium libraries, and browser setup.


Software Required for Selenium Automation

Software Purpose
Java JDK Used to write and execute Selenium code
Eclipse IDE / IntelliJ IDEA Used for writing code
Maven Used for dependency management
Selenium Library Provides Selenium classes and methods
Web Browser Browser to automate
Internet Connection Required for dependency downloads

Recommended Versions

Software Recommended Version
Java JDK JDK 17 or above
Eclipse Latest version
Maven Latest version
Selenium Selenium 4.6+
Chrome Browser Latest version

Step 1: Install Java JDK

Java is required because Selenium scripts are written and compiled using Java.

Download Java: Download Java JDK and install it according to your operating system.

Refer to the Java setup guide for detailed installation steps: https://prowessapps.com/java/java-environment-setup

Verify Java installation:

java -version

Example output:

java version "21.0.1"
Java(TM) SE Runtime Environment

Check Java compiler:

javac -version

Example output:

javac 21.0.1

Step 2: Configure JAVA_HOME

After installing Java, configure environment variables so Selenium and Maven can find the JDK.

Open:

  • Control Panel
  • System
  • Advanced System Settings
  • Environment Variables

Create a new system variable:

  • Variable Name: JAVA_HOME
  • Variable Value: C:\Program Files\Java\jdk-21

Add this path under System Path:

%JAVA_HOME%\bin

Verify the variable:

echo %JAVA_HOME%

Step 3: Install Eclipse IDE

Eclipse provides an environment for writing and executing Selenium scripts.

Install Eclipse: Download and install Eclipse IDE.

Recommended package: Eclipse IDE for Java Developers.

Step 4: Open Eclipse

Launch Eclipse and select your workspace.

Your workspace may look like:

C:\Users\Username\workspace

Click Launch to open Eclipse.

Step 5: Create Maven Project

Maven automatically manages project dependencies.

Navigate:

  • File → New → Other

Search for Maven Project.

Select:

  • Maven → Maven Project

Click Next.

Select workspace settings and make sure Create a simple project is unchecked.

Click Next.

Select archetype maven-archetype-quickstart from org.apache.maven.archetypes.

Click Next.

Enter project details:

  • Group Id: com.selenium
  • Artifact Id: SeleniumProject
  • Version: 1.0-SNAPSHOT
  • Package: com.selenium.tests

Click Finish.

Project Structure

After project creation, the structure should look like:

SeleniumProject
│
├── src/main/java
│
├── src/test/java
│
├── JRE System Library
│
├── Maven Dependencies
│
└── pom.xml

Understanding Project Structure

  • src/main/java contains application code.
  • src/test/java contains Selenium test scripts.
  • Maven Dependencies stores downloaded libraries.
  • pom.xml stores dependencies, plugins, project settings, and build configuration.

Step 6: Add Selenium Dependency

Open pom.xml and add the Selenium dependency.

<dependencies>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>4.33.0</version>
    </dependency>

</dependencies>

Save the file. Maven will download Selenium libraries automatically.

Step 7: Verify Selenium Installation

Create a Java class inside src/test/java.

Example:

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(driver.getTitle());

        driver.quit();

    }

}

Code Explanation

  • Create browser object: WebDriver driver = new ChromeDriver(); opens the Chrome browser.
  • Open URL: driver.get("https://www.google.com"); loads the website.
  • Get page title: driver.getTitle(); returns the page title.
  • Close browser: driver.quit(); closes all browser windows.

Browser Flow in Selenium 4.6+

Test Script
      ↓
Selenium WebDriver
      ↓
Selenium Manager
      ↓
Browser Driver
      ↓
Browser

Selenium Manager (Important)

  • Browser drivers download automatically.
  • Driver configuration is automatic.
  • No driver path setup is needed.
  • No separate ChromeDriver download is required.

Old Method (Not Recommended)

Earlier versions used explicit driver setup:

System.setProperty(
"webdriver.chrome.driver",
"C:\Drivers\chromedriver.exe"
);

WebDriver driver = new ChromeDriver();

In Selenium 4.6+, this is generally not required.

Common Errors

Java not recognized

Error: 'java' is not recognized

Solution: Configure JAVA_HOME correctly.

Selenium package error

Error: The import org.openqa cannot be resolved

Solution: Update the Maven project so dependencies are downloaded.

Browser session error

Error: session not created

Solution: Update the browser version to match the driver.

Best Practices

  • Use Selenium 4.6 or later.
  • Use Maven dependency management.
  • Keep your browser updated.
  • Use reusable methods.
  • Keep the project structure organized.
  • Avoid hardcoded values.

Software Required for Selenium Automation with Python

Software Purpose
Python Used to write Selenium scripts
IDE (PyCharm / VS Code) Used to write and execute code
Selenium Package Provides Selenium methods
Browser Browser to automate
Internet Connection Required to download packages

Recommended Versions

Software Recommended Version
Python Python 3.10+
Selenium Selenium 4.6+
VS Code Latest Version
Chrome Browser Latest Version

Step 1: Install Python

Download and install Python according to your operating system.

During installation, make sure to check Add Python to PATH.

Click Install Now.

Verify Python installation:

python --version

Example output:

Python 3.12.2

Check pip installation:

pip --version

Example output:

pip 24.0

Step 2: Install IDE

Popular IDEs include:

  • Visual Studio Code (recommended): lightweight, fast, multiple extensions, built-in terminal.
  • PyCharm: smart code suggestions, advanced debugging, better project management.

Step 3: Create Python Project

Example folder structure:

SeleniumProject
│
├── test.py
│
├── requirements.txt
│
└── venv

Step 4: Create Virtual Environment (Recommended)

Virtual environments isolate project packages.

Open terminal:

python -m venv venv

Activate the virtual environment:

Windows

venv\Scripts\activate

macOS/Linux

source venv/bin/activate

After activation, (venv) appears in the terminal.

Step 5: Install Selenium Package

Install Selenium:

pip install selenium

Verify installation:

pip show selenium

Example output:

Name: selenium
Version: 4.x.x

Step 6: Create Python File

Create a new file named test.py.

Step 7: Write First Selenium Script

from selenium import webdriver

driver = webdriver.Chrome()

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

print(driver.title)

driver.quit()

Code Explanation

  • Import webdriver: from selenium import webdriver imports Selenium browser classes.
  • Create browser object: driver = webdriver.Chrome() launches Chrome browser.
  • Open website: driver.get("https://www.google.com") navigates to the URL.
  • Get page title: print(driver.title) displays the page title.
  • Close browser: driver.quit() closes all browser windows.

Run Python Script

Open terminal and run:

python test.py

Expected output:

Google

Selenium Manager (Python Selenium 4.6+)

  • Browser drivers download automatically.
  • No separate ChromeDriver download required.
  • No driver path configuration.
  • Automatic browser-driver management.

Browser Flow

Python Script
      ↓
Selenium WebDriver
      ↓
Selenium Manager
      ↓
Browser Driver
      ↓
Browser

Old Method (Not Recommended)

Earlier versions required:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service(
    executable_path="C:/Drivers/chromedriver.exe"
)

driver = webdriver.Chrome(service=service)

This is usually unnecessary in Selenium 4.6+.

Common Errors

Python not recognized

Error: 'python' is not recognized

Solution: Reinstall Python and enable Add Python to PATH.

Selenium not found

Error: ModuleNotFoundError: No module named 'selenium'

Solution: Run pip install selenium.

Browser session error

Error: session not created

Solution: Update the browser version.

Best Practices

  • Use virtual environments.
  • Keep Selenium updated.
  • Use Selenium 4.6+.
  • Organize project files properly.
  • Keep reusable functions separate.
  • Avoid hardcoded values.

Next: First Selenium Script