Installing Selenium WebDriver in Python: A Quick Guide

 Here’s a quick and practical guide to installing and using Selenium WebDriver with Python. Selenium is widely used for automating web browser interaction for testing or scraping.


πŸš€ Step 1: Install Python

Make sure you have Python 3.x installed.


Check with:


bash

Copy code

python --version

Download from: https://www.python.org/downloads/


πŸ“¦ Step 2: Install Selenium

Use pip to install Selenium:


bash

Copy code

pip install selenium

🌐 Step 3: Download WebDriver

Selenium needs a WebDriver to interface with the browser (e.g., ChromeDriver for Chrome).


For Chrome:

Check your Chrome version:

Go to chrome://settings/help


Download the corresponding ChromeDriver:

https://sites.google.com/chromium.org/driver/


Extract it and add it to your PATH, or specify the path in your script.


πŸ§ͺ Step 4: Sample Selenium Script

Here’s a basic script to open a webpage:


python

Copy code

from selenium import webdriver

from selenium.webdriver.common.by import By


# Optional: Set options (e.g., headless)

options = webdriver.ChromeOptions()

# options.add_argument("--headless")


# Start Chrome

driver = webdriver.Chrome(options=options)


# Navigate to a site

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


# Find the search box and enter a query

search_box = driver.find_element(By.NAME, "q")

search_box.send_keys("Selenium WebDriver Python")

search_box.submit()


# Print page title

print(driver.title)


# Quit the browser

driver.quit()

πŸ› ️ Optional Tools

WebDriver Manager (avoids manual driver download):


bash

Copy code

pip install webdriver-manager

Example usage:


python

Copy code

from selenium import webdriver

from selenium.webdriver.chrome.service import Service

from webdriver_manager.chrome import ChromeDriverManager


driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))

✅ Summary

Step Description

Install Python Ensure Python 3 is set up

Install Selenium pip install selenium

Get WebDriver Download for your browser

Write Script Use Selenium commands to automate browser

Learn Selenium Python Training in Hyderabad

Read More

Why Use Python for Selenium Automation?

What is Selenium? A Beginner’s Guide for Python Developers

Comparing Selenium with Python vs Selenium with Java: Which One to Choose?

How to Integrate Selenium with Python Logging for Better Test Reports

Visit Our IHUB Talent Training Institute in Hyderabad

Get Directions

Comments

Popular posts from this blog

How to Install and Set Up Selenium in Python (Step-by-Step)

Feeling Stuck in Manual Testing? Here’s Why You Should Learn Automation Testing

A Beginner's Guide to ETL Testing: What You Need to Know