Setup notes for getting Selenium working with Python on Windows. Validate with a small smoke test and use the backups if something fails.
This is the “happy path” I use now for Selenium in Python on Windows. Do it in a fresh project folder.
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 --versionYou can use py -3 in later steps if needed.
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\activatepython -m pip install --upgrade pip setuptools wheelpip install selenium webdriver-managerWhy 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.
- 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.
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.pyExpected: Chrome opens → Google loads → search runs → title prints → window closes.
(venv)visible in your prompt → you’re in the right Python.pip listshowsseleniumandwebdriver-manager.- The script runs without a “driver not found” error.
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:
pytestorunittest. - Maintainability: Page Object Model (POM).
- Running headless for CI.
These are the “don’t panic, do this” checks for the most common failures.
- 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).
- 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.
- Check your internet connection or firewalls.
- Try a simpler site:
driver.get("https://example.com")- Add an explicit wait for elements before interacting.
- Use a temporary bypass just for the current shell:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass- Use the launcher explicitly:
py -3 -m venv venv
venv\Scripts\activate
py -3 -m pip install --upgrade pipSometimes 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-managerNow rerun the smoke test.
If your training or project uses a different browser, swap the driver manager import and the webdriver constructor.
from selenium import webdriver
from selenium.webdriver.edge.service import Service
from webdriver_manager.microsoft import EdgeChromiumDriverManager
driver = webdriver.Edge(service=Service(EdgeChromiumDriverManager().install()))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.
- 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- 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.
- Locators cheatsheet: see
locators_cheatsheet.md - Second demo script with waits: run
python test_selenium_waits.py