A collection of Selenium WebDriver scripts for browser automation, web scraping, and automated testing.
selenium/
├── README.md # Main repository documentation
├── .gitignore # Git ignore patterns
├── requirements.txt # Python dependencies
├── docs/
│ ├── SETUP_GUIDE.md # WebDriver setup and configuration
│ └── BEST_PRACTICES.md # Selenium best practices
├── drivers/ # WebDriver executables
│ ├── chromedriver
│ └── geckodriver
└── scripts/
├── browser-automation/ # Browser automation scripts
│ ├── README.md
│ └── confluence.py # Confluence page automation
├── web-scraping/ # Web scraping scripts
│ └── README.md
├── navigation-tests/ # Navigation and page load tests
│ └── README.md
└── utilities/ # Helper functions and utilities
├── README.md
└── quitBrowser.py # Browser cleanup utility
- Python 3.7+ installed
- pip package manager
- Chrome or Firefox browser installed
- WebDriver for your browser (ChromeDriver or GeckoDriver)
- Clone the repository:
git clone https://github.com/sjamal/selenium.git
cd selenium- Create and activate virtual environment:
python -m venv venv
source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windows- Install dependencies:
pip install -r requirements.txt-
Download WebDriver:
- Chrome: ChromeDriver
- Firefox: GeckoDriver
- Place in
drivers/directory
-
Make driver executable (macOS/Linux):
chmod +x drivers/chromedriver
chmod +x drivers/geckodriver# Activate virtual environment
source venv/bin/activate
# Run a script
python scripts/browser-automation/confluence.py
# Deactivate when done
deactivate- SETUP_GUIDE.md - WebDriver installation and configuration
- BEST_PRACTICES.md - Selenium best practices and patterns
Scripts for automating browser interactions and web page manipulation.
Scripts:
- confluence.py - Automate Confluence page creation and content posting
Scripts for extracting data from web pages.
Scripts for testing navigation, page loads, and user flows.
Helper functions and reusable code.
Scripts:
- quitBrowser.py - Safe browser cleanup and resource management
- Python 3.7 or higher
- Selenium 3.141+
- Chrome/Firefox browser
- ChromeDriver/GeckoDriver WebDriver
- ~300MB disk space for dependencies
| Package | Version | Purpose |
|---|---|---|
| selenium | 3.141+ | WebDriver automation |
| webdriver-manager | 3.3+ | Automatic driver management |
| beautifulsoup4 | 4.9+ | HTML parsing (optional) |
| requests | 2.26+ | HTTP requests (optional) |
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# Configure options
chrome_options = Options()
chrome_options.add_argument("--incognito")
# Create driver
driver = webdriver.Chrome(
executable_path="./drivers/chromedriver",
options=chrome_options
)
# Navigate
driver.get("https://example.com")
print(f"Title: {driver.title}")
# Close browser
driver.quit()from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# Wait for element
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "element_id"))
)
# Find elements
element = driver.find_element(By.ID, "element_id")
elements = driver.find_elements(By.CLASS_NAME, "class_name")# Click
element.click()
# Type text
element.send_keys("text to type")
# Submit form
element.submit()
# Get text
text = element.text
# Get attribute
attr_value = element.get_attribute("href")# Download WebDriver
# Chrome: https://chromedriver.chromium.org/
# Firefox: https://github.com/mozilla/geckodriver/releases
# Place in drivers/ directory
# Make executable (macOS/Linux)
chmod +x drivers/chromedriver# Use explicit wait
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "element_id"))
)# Update WebDriver to match browser version
# Chrome version: Check chrome://version/
# Update drivers/ with matching ChromeDriver version- Always use waits - Avoid hard-coded
time.sleep() - Use explicit waits - More reliable than implicit waits
- Handle exceptions - Gracefully handle errors
- Close browsers - Use try/finally or context managers
- Use headless mode - For CI/CD pipelines
Sarosh Jamal
When adding new scripts:
- Create in appropriate category directory
- Include comprehensive documentation
- Test thoroughly in multiple browsers
- Follow existing code style
- Update REQUIREMENTS.txt if adding dependencies
- Update relevant README files