Skip to content

Instantly share code, notes, and snippets.

@Sh-ui
Created September 4, 2025 02:06
Show Gist options
  • Select an option

  • Save Sh-ui/ab07684376048d5276836119f11948ea to your computer and use it in GitHub Desktop.

Select an option

Save Sh-ui/ab07684376048d5276836119f11948ea to your computer and use it in GitHub Desktop.
Selenium + Python setup guide for Windows with backup plans, locators cheat sheet, and demo scripts.

Getting Selenium Running on Windows (setup notes)

Setup notes for getting Selenium working with Python on Windows. Validate with a small smoke test and use the backups if something fails.


main setup

This is the “happy path” I use now for Selenium in Python on Windows. Do it in a fresh project folder.

Step 0: check Python

python --version
  • If you see Python 3.x → good.
  • If you get “not recognized” → install Python 3, and check the box to “Add Python to PATH” during install.
  • If multiple Pythons are installed and PATH is messy, pin the launcher:
py -3 --version

You can use py -3 in later steps if needed.

Step 1: create a clean virtual environment

python -m venv venv
venv\Scripts\activate
  • You should see (venv) appear in your prompt. That means you’re in the sandbox.
  • If activation fails in PowerShell due to policy restrictions:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
venv\Scripts\activate

Step 2: upgrade the basic tooling

python -m pip install --upgrade pip setuptools wheel

Step 3: install Selenium + WebDriver manager

pip install selenium webdriver-manager

Why WebDriver manager? Because manually downloading and PATH-ing chromedriver.exe is how 90% of people get stuck. This helper grabs the matching driver for the installed browser automatically.

Step 4: make sure the browser you’ll test is present

  • Default assumption: Chrome.
  • Alternative: Edge or Firefox work too (notes below), but let’s keep the first pass simple with Chrome.
  • Make sure the browser is up to date. Auto-update is fine.

Step 5: first smoke test

Create test_selenium.py in your project folder with this:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

# Launch browser
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get("https://www.google.com")

# Do a simple search
box = driver.find_element(By.NAME, "q")
box.send_keys("QA training with Selenium")
box.send_keys(Keys.RETURN)

print(driver.title)
driver.quit()

Run it:

python test_selenium.py

Expected: Chrome opens → Google loads → search runs → title prints → window closes.

Step 6: sanity checklist

  • (venv) visible in your prompt → you’re in the right Python.
  • pip list shows selenium and webdriver-manager.
  • The script runs without a “driver not found” error.

Step 7: you’re ready for QA training

You’ve proven the plumbing. Next topics to learn (in this order):

  • Locators: By.ID, By.NAME, By.XPATH, By.CSS_SELECTOR.
  • Waits: WebDriverWait + expected conditions (pages are async, waits are your best friend).
  • Test structure: pytest or unittest.
  • Maintainability: Page Object Model (POM).
  • Running headless for CI.

when things go sideways (fast fixes)

These are the “don’t panic, do this” checks for the most common failures.

“chromedriver not found” or driver mismatch

  • You’re probably not using WebDriver manager, or it didn’t install correctly.
  • Fix:
pip install --upgrade webdriver-manager
  • Make sure your script uses it (see the Service(ChromeDriverManager().install()) line in the smoke test).

Browser opens then closes immediately

  • That’s normal; the script calls driver.quit() at the end.
  • Comment it out while you’re experimenting if you want the window to stay open.

Timeout errors when loading pages

  • Check your internet connection or firewalls.
  • Try a simpler site:
driver.get("https://example.com")
  • Add an explicit wait for elements before interacting.

Activation policy blocks the venv

  • Use a temporary bypass just for the current shell:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

PATH mystery: multiple Pythons installed

  • Use the launcher explicitly:
py -3 -m venv venv
venv\Scripts\activate
py -3 -m pip install --upgrade pip

clean-room reset (when the environment feels cursed)

Sometimes the fastest route is to start over clean, without touching the global machine state.

# from your project folder
rmdir /s /q venv
python -m venv venv
venv\Scripts\activate
pip install selenium webdriver-manager

Now rerun the smoke test.


alternatives: Edge and Firefox

If your training or project uses a different browser, swap the driver manager import and the webdriver constructor.

Microsoft Edge

from selenium import webdriver
from selenium.webdriver.edge.service import Service
from webdriver_manager.microsoft import EdgeChromiumDriverManager

driver = webdriver.Edge(service=Service(EdgeChromiumDriverManager().install()))

Firefox

from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from webdriver_manager.firefox import GeckoDriverManager

driver = webdriver.Firefox(service=Service(GeckoDriverManager().install()))

Everything else (locators, waits, test structure) stays the same.


tiny cheatsheet (copy/paste fuel)

  • Create + enter venv
python -m venv venv
venv\Scripts\activate
  • Install deps
pip install --upgrade pip setuptools wheel
pip install selenium webdriver-manager
  • Run the test
python test_selenium.py
  • Nuke and recreate venv
rmdir /s /q venv
python -m venv venv

final notes

  • Keep your browser updated. If it auto-updates and something suddenly breaks, re-run with WebDriver manager. It will fetch a compatible driver.
  • Use waits early. Flaky tests are usually just “clicked before it existed.”
  • Don’t be afraid to start fresh in a new venv. It’s a feature, not a failure.

If you like this pragmatic format, it’s the same spirit I used when tweaking my terminal setup: iterate, measure, and keep what works.


extras

  • Locators cheatsheet: see locators_cheatsheet.md
  • Second demo script with waits: run python test_selenium_waits.py

Selenium Locators: Quick Reference

  • Use these in find_element or find_elements.
  • Prefer stable, unique attributes. Keep selectors simple.

common choices

  • By.ID: reliable when the id is unique
  • By.NAME: handy for form fields
  • By.CSS_SELECTOR: fast and flexible
  • By.XPATH: powerful for tricky DOMs, use sparingly

examples

from selenium.webdriver.common.by import By

# ID
el = driver.find_element(By.ID, "search")

# NAME
el = driver.find_element(By.NAME, "q")

# CSS
el = driver.find_element(By.CSS_SELECTOR, "input[name='q']")

# XPath
el = driver.find_element(By.XPATH, "//input[@name='q']")

tips

  • Start with ID. If not available, try CSS.
  • Avoid brittle selectors that depend on layout-only classes.
  • Use explicit waits before interacting with elements that load asynchronously.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
# Launch Chrome with webdriver-manager
_driver_service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=_driver_service)
try:
driver.get("https://duckduckgo.com/")
wait = WebDriverWait(driver, 10)
# Wait for the search box, then search
search_box = wait.until(EC.presence_of_element_located((By.NAME, "q")))
search_box.send_keys("selenium python waits")
search_box.submit()
# Wait for the results title to include the query
wait.until(EC.title_contains("selenium python waits"))
print(driver.title)
finally:
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment