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
Comments
Post a Comment