Skip to content

sjamal/selenium

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Selenium Scripts Repository

A collection of Selenium WebDriver scripts for browser automation, web scraping, and automated testing.

Repository Structure

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

Quick Start

Prerequisites

  • Python 3.7+ installed
  • pip package manager
  • Chrome or Firefox browser installed
  • WebDriver for your browser (ChromeDriver or GeckoDriver)

Installation

  1. Clone the repository:
git clone https://github.com/sjamal/selenium.git
cd selenium
  1. Create and activate virtual environment:
python -m venv venv
source venv/bin/activate  # macOS/Linux
venv\Scripts\activate     # Windows
  1. Install dependencies:
pip install -r requirements.txt
  1. Download WebDriver:

  2. Make driver executable (macOS/Linux):

chmod +x drivers/chromedriver
chmod +x drivers/geckodriver

Running Scripts

# Activate virtual environment
source venv/bin/activate

# Run a script
python scripts/browser-automation/confluence.py

# Deactivate when done
deactivate

Documentation

Setup and Configuration

Script Categories

🤖 Browser Automation

Scripts for automating browser interactions and web page manipulation.

Scripts:

  • confluence.py - Automate Confluence page creation and content posting

Full Documentation

🕷️ Web Scraping

Scripts for extracting data from web pages.

Full Documentation

🧪 Navigation Tests

Scripts for testing navigation, page loads, and user flows.

Full Documentation

🛠️ Utilities

Helper functions and reusable code.

Scripts:

  • quitBrowser.py - Safe browser cleanup and resource management

Full Documentation

System Requirements

  • Python 3.7 or higher
  • Selenium 3.141+
  • Chrome/Firefox browser
  • ChromeDriver/GeckoDriver WebDriver
  • ~300MB disk space for dependencies

Common Packages

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)

Quick Examples

Basic Browser Automation

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()

Finding Elements

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")

Interacting with Elements

# 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")

Troubleshooting

WebDriver Not Found

# 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

Element Not Found

# 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"))
)

Session Not Created

# Update WebDriver to match browser version
# Chrome version: Check chrome://version/
# Update drivers/ with matching ChromeDriver version

Tips and Best Practices

  1. Always use waits - Avoid hard-coded time.sleep()
  2. Use explicit waits - More reliable than implicit waits
  3. Handle exceptions - Gracefully handle errors
  4. Close browsers - Use try/finally or context managers
  5. Use headless mode - For CI/CD pipelines

Author

Sarosh Jamal

Contributing

When adding new scripts:

  1. Create in appropriate category directory
  2. Include comprehensive documentation
  3. Test thoroughly in multiple browsers
  4. Follow existing code style
  5. Update REQUIREMENTS.txt if adding dependencies
  6. Update relevant README files

Resources

About

Python browser automation scripts for Confluence page creation and web workflows, built with Selenium 4 and webdriver-manager.

Topics

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages