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

 Here’s your step-by-step guide to installing and setting up Selenium in Python — perfect if you're just getting started with browser automation. πŸš€


🐍 Step 1: Install Python

If you haven’t already:


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


Make sure to check the box "Add Python to PATH" during installation


Verify installation:


bash

Copy

Edit

python --version

pip --version

πŸ“¦ Step 2: Install Selenium Library

Open your terminal or command prompt and run:


bash

Copy

Edit

pip install selenium

To verify:


bash

Copy

Edit

pip show selenium

🌐 Step 3: Download WebDriver for Your Browser

Depending on what browser you want to automate:


πŸ”Ή Chrome:

Download ChromeDriver:

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


Make sure the driver version matches your installed Chrome version.


πŸ”Ή Firefox:

Download GeckoDriver:

➡️ https://github.com/mozilla/geckodriver/releases


Unzip and place the executable somewhere on your system, like:


Windows: C:\WebDrivers\


Mac/Linux: /usr/local/bin/


✅ Step 4: Basic Selenium Script

πŸ”Έ Example: Open Google in Chrome

python

Copy

Edit

from selenium import webdriver

from selenium.webdriver.chrome.service import Service

from selenium.webdriver.common.by import By


# Optional: path to your chromedriver

service = Service('path/to/chromedriver')  # e.g., 'C:/WebDrivers/chromedriver.exe'

driver = webdriver.Chrome(service=service)


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

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


driver.quit()

⚙️ Optional: Use webdriver-manager to Skip Manual Driver Download

This tool automatically downloads and manages the driver binaries for you:


bash

Copy

Edit

pip install webdriver-manager

Example with webdriver-manager:

python

Copy

Edit

from selenium import webdriver

from selenium.webdriver.chrome.service import Service

from webdriver_manager.chrome import ChromeDriverManager


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

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

print("Title:", driver.title)

driver.quit()

πŸ§ͺ Step 5: Run Your Script

Save your Python file, e.g., selenium_test.py


Run it from the terminal:


bash

Copy

Edit

python selenium_test.py

You should see a browser window open, navigate to Google, and then close after printing the page title.


🎁 Bonus: Automate More!

You can now:


Locate elements with driver.find_element(By.ID, ...)


Simulate typing: element.send_keys("search term")


Click buttons: element.click()


Want help with automating login, form filling, or scraping? Just ask — happy to help!

Learn Selenium Python Course

Read More

How do I install and set up Selenium in Python?

Introduction to Selenium with Python: What & Why?

Visit Our IHUB Talent Training Institute in Hyderabad

Get Directions

Comments

Popular posts from this blog

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