Installing Selenium in Python Step-by-Step

Selenium is a powerful open-source tool used for automating web browsers. With Python’s simplicity and Selenium’s capabilities, testers and developers can create robust web automation scripts quickly and easily. If you're new to automation, this step-by-step guide will help you install Selenium in Python and set up your first test script.

Step 1: Install Python

Before using Selenium, make sure Python is installed on your system.

Visit the official Python website.

Download the latest version and run the installer.

During installation, ensure you check the box “Add Python to PATH”.

To verify installation, open a terminal or command prompt and type:

Step 2: Install pip (Python Package Installer)

In most recent Python installations, pip is included by default. To check if it's available, type:

If not installed, you can follow the instructions from the pip documentation.

Step 3: Install Selenium Using pip

Once Python and pip are set up, install Selenium using the command

This will download and install the latest version of Selenium into your Python environment.

Step 4: Download WebDriver (e.g., ChromeDriver)

Selenium requires a WebDriver to communicate with the browser. For Google Chrome:

Visit the ChromeDriver downloads page.

Download the version that matches your Chrome browser.

Extract the file and note its path (you'll need this in your script).

Step 5: Write and Run Your First Script

Here’s a basic example that opens Google and prints the title:

from selenium import webdriver

# Set the path to the ChromeDriver

driver = webdriver.Chrome(executable_path="C:/path/to/chromedriver.exe")

# Open a website

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

# Print the title of the page

print("Page title is:", driver.title)

# Close the browser

driver.quit()

Make sure to replace the path with the actual location of your chromedriver.exe.

Conclusion

Installing Selenium in Python is simple and fast. Once set up, you can automate a wide range of tasks in your browser—from testing web applications to scraping data. With just a few lines of code, you’re ready to explore the powerful world of browser automation!

Learn Selenium with Python Training Course

Read more  What is Selenium and Why Use It with Python?

Visit our Quality Thought Institute

Get Direction










Comments

Popular posts from this blog

Understanding the useEffect Hook

What Is Tosca? A Beginner’s Guide

Exception Handling in Java