⚙ Selenium with Python – Installation & Setup Guide
Before starting automation with Selenium, we need a proper environment setup. This includes installing Python, VS Code, Selenium, WebDriver, and configuring everything correctly.
🐍 Installing Python
Python is the programming language used to write Selenium automation scripts.
- Download Python from official website
- Run the installer
- Check ✅ “Add Python to PATH”
- Complete installation
Verify installation:
python --version---
🧑💻 Installing VS Code
Visual Studio Code (VS Code) is a lightweight and powerful code editor used for Python automation development.
- Download VS Code
- Install it on your system
- Open VS Code
⚙ VS Code Setup for Python Automation
To use Python in VS Code, install the required extensions.
- Python (by Microsoft)
- Pylance
- Python Debugger
After installation:
- Select Python Interpreter
- Create a project folder
- Create a file:
test.py
📦 Installing Selenium in Python
Selenium can be installed using pip (Python package manager).
pip install selenium
Verify installation:
pip show selenium---
🌐 Installing WebDriver (ChromeDriver, EdgeDriver, GeckoDriver)
WebDriver is required to control browsers.
- Chrome → ChromeDriver
- Firefox → GeckoDriver
- Edge → EdgeDriver
Steps:
- Check your browser version
- Download matching WebDriver version
- Extract the driver file
🛠 Setting WebDriver Path
There are two ways to set WebDriver path:
- Add driver folder to system environment variables
from selenium import webdriver driver = webdriver.Chrome(executable_path="C:/drivers/chromedriver.exe")---
🚀 First Selenium Script in Python
Here is your first Selenium automation script:
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome()
driver.get("https://www.google.com")
time.sleep(3)
driver.quit()
- Open Chrome browser
- Open Google website
- Wait for 3 seconds
- Close the browser
▶ Running Selenium Script in VS Code
Steps to run Selenium script:
- Open project folder in VS Code
- Open terminal
- Run command:
python test.py
OR
- Right click on file
- Click Run Python File in Terminal
After completing this setup, your system is fully ready for Selenium automation with Python. Now you can start writing real automation scripts, building frameworks, and creating professional automation projects.
No comments:
Post a Comment