This guide walks you through installing the required tools, configuring Selenium WebDriver with Python, and writing your first automated test that opens a browser, interacts with a page, and verifies the result automatically. By the end, you will have a repeatable test you can run with a single command and extend to cover more of your application.
Get business pricing on monitors, keyboards and dev gear
- Business-only prices and quantity discounts
- Tax-exempt purchasing
- Multiple users, one account, clear invoices

AI for Quality Assurance and Software Testing: The Practitioner’s Complete Guide to AI-Powered Testing, Tools, and Transformation
- ✔ Format: Practitioner’s guide (ebook/print)
- ✔ Focus: AI-powered testing tools and QA transformation
- ✔ Audience: QA engineers and test leads

AI-Assisted QA and Software Testing with Claude Code
- ✔ Format: Tool-focused technical guide
- ✔ Tool: Claude Code
- ✔ Testing types: Unit, integration, and end-to-end

Spec-Driven Software Testing with AI: Build Reliable Test Suites from Specifications
- ✔ Format: Methodology-focused technical book
- ✔ Series: Spec-Driven AI Engineering Series
- ✔ Topics: AI, specification-driven testing, test automation, TDD, API testing, CI/CD
This guide is written for developers and QA beginners who have basic command-line and programming familiarity but no prior test automation experience. No commercial tools or licenses are required — everything used here is free and open source. Expect to spend 45 to 60 minutes, including installation.
While many automation tools exist (Playwright, Cypress, Katalon, TestComplete), Selenium is used here because it is free, works with every major browser and language, and its concepts transfer directly to other tools. If you learn the pattern of open page, act, assert here, you can apply it anywhere.
Difficulty: Beginner | Time: 45-60 minutes
What You’ll Need
Tools & Materials:
- A computer with Windows, macOS, or Linux and at least 4 GB of free RAM
- Python 3.9 or newer, downloadable from python.org (check ‘Add Python to PATH’ during Windows installation)
- Google Chrome or Firefox installed
- A text editor or IDE — Visual Studio Code is free and works well
- A terminal or command prompt
Knowledge:
- Basic command-line use (opening a terminal, running commands)
- Fundamental Python syntax (variables, functions, imports)
- Basic understanding of HTML elements and attributes (id, name, class)
You do not need to download browser drivers manually anymore. Selenium 4.6 and later include Selenium Manager, which downloads and updates the correct driver for your installed browser automatically. If you find older tutorials instructing you to download chromedriver.zip files and place them on your system PATH, skip those steps — they are outdated and a common source of version-mismatch errors.
AI for Quality Assurance and Software Testing: The Practitioner’s Complete Guide to AI-Powered Testing, Tools, and Transformation

This guide earns our top spot because it frames AI-powered testing as a practice-wide transformation rather than a single tool or technique. Where AI-Assisted QA with Claude Code teaches you one automation workflow in depth, this book zooms out to cover AI testing tools alongside strategy, process change, and team adoption — the context most QA organizations actually struggle with.The practical application focus is its strongest asset. Rather than dwelling on theory, it walks through how AI changes test generation, maintenance, and coverage decisions. Compared with Spec-Driven Software Testing with AI, which assumes you can write specifications precisely, this guide meets practitioners where they are and shows how to evolve existing QA processes incrementally.The tradeoff is depth. Because it spans tools and transformation, it cannot match the step-by-step specificity of a single-tool book. Readers who want copy-paste workflows for one environment will finish this and still need a follow-up resource.
Pros:
- Broadest coverage of AI applications across the entire QA lifecycle
- Balances tool instruction with process and transformation guidance
- Practitioner-oriented rather than purely theoretical
- Serves as a durable reference as tools change
Cons:
- Less hands-on depth than single-tool guides
- Some tool-specific content may age quickly
- Not a step-by-step implementation manual
Best for: QA engineers, test leads, and engineering managers who want a comprehensive grounding in AI-driven testing strategy
Not ideal for: Developers who want a tight, tool-specific automation cookbook
Bottom line: The most well-rounded starting point for teams bringing AI into software testing automation.
“The most well-rounded starting point for teams bringing AI into software testing automation.”
AI-Assisted QA and Software Testing with Claude Code

If our top pick is the map, this book is the vehicle. It centers on automating testing workflows with Claude Code, and that singular focus pays off in concreteness: you follow real workflows rather than abstract principles. It covers unit, integration, and end-to-end testing, which means a working developer can read it and apply it the same day.Compared with the Practitioner’s Complete Guide, this title trades breadth for immediate applicability. You will not find much on organizational transformation, but you will find how AI assistance changes the mechanics of writing and maintaining tests at every level of the stack. That makes it the better second purchase for teams whose strategy is already set and who need execution help.The obvious limitation is tool lock-in. Everything is anchored to Claude Code, so teams standardized on other AI assistants may find portions of the material translate imperfectly. It also presumes comfort with development workflows.
Pros:
- Covers all three major testing levels in one workflow
- Highly actionable with concrete automation examples
- Shows how AI assistance fits into real developer workflows
- Fastest path from reading to implementation
Cons:
- Tied to a single AI tool ecosystem
- Assumes existing coding proficiency
- Little coverage of QA strategy or process
Best for: Developers and automation engineers already working in code who want AI-accelerated test writing
Not ideal for: Manual testers or managers seeking strategy-level guidance
Bottom line: The most immediately practical pick for developers who want AI-assisted test automation they can use today.
“The most immediately practical pick for developers who want AI-assisted test automation they can use today.”
Spec-Driven Software Testing with AI: Build Reliable Test Suites from Specifications

This title takes the most intellectually disciplined approach of the three: instead of asking which tool to use, it asks where tests should come from in the first place. Building reliable test suites from specifications addresses the root cause of fragile automation — tests written against guesswork rather than documented behavior.Its coverage is impressive in scope: test automation, test-driven development, API testing, and CI/CD integration. That combination positions it between our other picks — more methodological than the Claude Code book, more implementation-focused than the transformation guide. As part of a Spec-Driven AI Engineering Series, it also rewards readers investing in that whole methodology.The tradeoff is a steeper on-ramp. Specification-driven testing demands up-front discipline: writing precise specs before generating tests. Teams with loosely documented requirements will need to change habits first, and readers outside the series may find some assumed context.
Pros:
- Roots test automation in specifications for long-term reliability
- Spans TDD, API testing, and CI/CD pipeline integration
- Reduces test flakiness by design rather than patching symptoms
- Fits a coherent broader engineering series
Cons:
- Requires disciplined specification writing up front
- Steeper learning curve than tool-focused guides
- Series context may feel incomplete as a standalone read
Best for: Engineers and architects who value maintainable, spec-anchored test suites and use CI/CD pipelines
Not ideal for: Teams without clear specifications or those wanting quick tactical wins
Bottom line: The strongest choice for teams that want durable, specification-driven test automation rather than quick tool adoption.
“The strongest choice for teams that want durable, specification-driven test automation rather than quick tool adoption.”
As an Amazon Associate we earn from qualifying purchases.
Before You Start
Close other running instances of the browser you will test with, since some driver conflicts arise from multiple sessions. Also decide what you will test. This guide tests a public demo page (the-internet.herokuapp.com) so the steps work for everyone, but you can substitute your own site’s URL and element locators as you go.
One warning worth acting on before you begin: automated tests should never run against a production system containing real customer data unless you explicitly own that environment and have permission. Use a demo site, a local development server, or a dedicated test environment.
Step-by-Step Instructions
Step 1: Verify Python is installed and working
Open a terminal and run:
python –version
If the output shows Python 3.9 or higher, continue. If you see ‘command not found’ or a version below 3.9, download the installer from python.org, run it, and on Windows check the box labeled ‘Add Python to PATH’ before clicking Install. Reopen the terminal afterward and run the command again.
Tip: On macOS and Linux, the command may be python3 instead of python. Use whichever works and use that same name in later commands.
Check: The terminal prints a Python version of 3.9 or higher with no error message.
Step 2: Create a project folder and virtual environment
Run these commands one at a time to create an isolated project:
mkdir my-tests
cd my-tests
python -m venv venv
Then activate the virtual environment. On Windows run venv\Scripts\activate. On macOS or Linux run source venv/bin/activate.
The virtual environment keeps your test dependencies separate from your system Python so nothing else on your machine breaks.
Tip: If Windows PowerShell blocks the activation script, run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser once, then retry activation.
Check: Your terminal prompt now begins with (venv).
Step 3: Install Selenium
With the virtual environment active, run:
pip install selenium
Wait for the installation to finish. Then run pip show selenium to confirm the installed version is 4.6 or higher, which guarantees the automatic driver download feature is available.
Tip: If pip is not recognized, try python -m pip install selenium instead.
Check: pip show selenium prints a version of 4.6 or greater.
Step 4: Write a first script that opens a browser
Create a file named test_smoke.py in your project folder and paste the following:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get(“https://the-internet.herokuapp.com/login”)
print(driver.title)
driver.quit()
This is a smoke test: it confirms the page loads and returns a title. Save the file.
Tip: Firefox users should replace webdriver.Chrome() with webdriver.Firefox(). Everything else stays the same.
Check: Saving produces no syntax errors and the file appears in your project folder.
Step 5: Run the script and confirm the browser opens
In your terminal, run:
python test_smoke.py
A Chrome window should open, load the login page, print the page title (The Internet) in your terminal, and close automatically. This first run may take an extra 20 to 30 seconds while Selenium Manager downloads the driver.
Tip: Do not manually close the browser window mid-run; let the script’s driver.quit() call close it so the driver process shuts down cleanly.
Check: The browser opened, displayed the login page, closed on its own, and the terminal printed ‘The Internet’.
Step 6: Add actions and assertions to make it a real test
Replace the contents of test_smoke.py with a fuller test that logs in and verifies the outcome:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
driver.get(“https://the-internet.herokuapp.com/login”)
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, “username”)))
driver.find_element(By.ID, “username”).send_keys(“tomsmith”)
driver.find_element(By.ID, “password”).send_keys(“SuperSecretPassword!”)
driver.find_element(By.CSS_SELECTOR, “button[type=’submit’]”).click()
flash = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, “flash”)))
assert “You logged into a secure area!” in flash.text, “Login success message not found”
print(“TEST PASSED”)
driver.quit()
This follows the core automation pattern: locate an element, act on it, wait for the result, and assert the expected outcome.
Tip: The explicit WebDriverWait is not optional decoration. Pages load asynchronously, and asserting before an element appears is the single most common cause of flaky, unreliable tests.
Check: Running python test_smoke.py fills in the credentials, clicks the button, and prints ‘TEST PASSED’.
Step 7: Convert the script into a repeatable test suite with pytest
Install pytest and add automatic waiting by running:
pip install pytest
Create a file named test_login.py containing:
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
@pytest.fixture
def driver():
driver = webdriver.Chrome()
driver.implicitly_wait(10)
yield driver
driver.quit()
def test_login_success(driver):
driver.get(“https://the-internet.herokuapp.com/login”)
driver.find_element(By.ID, “username”).send_keys(“tomsmith”)
driver.find_element(By.ID, “password”).send_keys(“SuperSecretPassword!”)
driver.find_element(By.CSS_SELECTOR, “button[type=’submit’]”).click()
assert “You logged into a secure area!” in driver.find_element(By.ID, “flash”).text
Run the suite with:
pytest -v
The fixture opens a fresh browser for each test and closes it afterward, keeping tests independent and repeatable.
Tip: Always name test files and test functions starting with ‘test_’ — pytest only discovers and runs items with that prefix.
Check: pytest -v prints ‘test_login.py::test_login_success PASSED’ with a green dot or PASSED marker and exits with no failures.
Common Mistakes to Avoid
- Manually downloading chromedriver and hitting version mismatches after a browser update — Use Selenium 4.6+ and let Selenium Manager fetch the driver automatically. Never pin a driver file in your project unless you have a specific locked-down environment.
- Locating elements immediately after page load and getting NoSuchElementException errors — Always wait for elements before interacting with them. Use WebDriverWait with expected_conditions for dynamic pages, or an implicit wait as a baseline safety net.
- Using fragile locators like absolute XPath positions or auto-generated CSS classes — Prefer stable locators in this order: element id, name attribute, data-testid attribute, then readable CSS selectors. Ask developers to add data-testid attributes to key elements.
- Writing one giant test that performs many actions, making failures hard to diagnose — Keep each test focused on one behavior with one clear assertion. When a focused test fails, you know immediately what broke.
Troubleshooting
Problem: Error: ‘chromedriver executable needs to be in PATH’ or ‘session not created: This version of ChromeDriver only supports Chrome version X’
Solution: Update Selenium by running pip install -U selenium, and update Chrome to the latest version, then retry. If it persists, delete any old chromedriver binaries from your PATH so Selenium Manager takes over.
Problem: TimeoutException while waiting for an element
Solution: Verify your locator matches the actual page by opening developer tools (F12), inspecting the element, and confirming the id or selector. If the element sits inside an iframe, first call driver.switch_to.frame() before locating it.
Problem: pytest finds no tests and exits immediately
Solution: Confirm the filename begins with test_ and each test function name begins with test_. Also confirm you are running pytest from inside the project folder where the file lives.
Problem: Browser window opens but stays blank or the script hangs
Solution: This is usually a network or proxy issue preventing the driver from fetching the page. Check your internet connection, disable VPN temporarily, and try a different site to isolate whether the problem is the target site or your environment.
What Success Looks Like
Your setup is complete and correct when all of the following are true:
- Running pytest -v from your project folder opens a browser, performs the login flow, and reports 1 passed with zero failures.
- The browser opens and closes automatically without you touching it.
- Running the suite a second time produces the identical passing result, confirming the test is stable rather than lucky.
- Breaking the test on purpose (change the password to ‘wrong’) makes it fail with a clear AssertionError, proving your assertion actually verifies behavior.
Next Steps
With a working foundation in place, extend it gradually:
- Add a negative test that submits wrong credentials and asserts the error message appears.
- Point the tests at your own application by substituting your URL and locators — inspect elements with browser developer tools to find stable ids.
- Group repeated setup (login, navigation) into shared pytest fixtures in a conftest.py file.
- Once your suite grows past roughly a dozen tests, set up continuous integration with GitHub Actions so tests run automatically on every code change.
- If your application is heavily JavaScript-based and you want faster, more modern tooling, evaluate Playwright as a next tool — the open, act, assert pattern you just learned transfers directly.
Avoid the temptation to automate everything at once. Grow the suite test by test, keeping every test passing before adding the next.
Frequently Asked Questions
Do I need to download ChromeDriver manually?
No. Selenium 4.6 and later include Selenium Manager, which detects your browser version and downloads the matching driver automatically the first time you run a test. Manual driver downloads are only needed for legacy Selenium 3 installations or restricted corporate environments.
Selenium, Playwright, or Cypress — which should I choose?
Start with any one; the skills transfer. Selenium has the broadest browser and language support and the largest community. Playwright is faster with better built-in waiting and is the common modern choice for new projects. Cypress is developer-friendly but runs only in JavaScript and has weaker multi-tab/multi-domain support. For a first automation setup, Selenium with Python is the lowest-friction path.
Why do my tests sometimes pass and sometimes fail randomly?
Random failures (flakiness) almost always come from timing: the test asserts or clicks before the page has finished loading or an element has appeared. Fix it by replacing sleep() calls with explicit WebDriverWait conditions, and by making locators specific enough to match exactly one element.
How do I run tests without a visible browser window?
Add headless mode by creating the driver with options: create an Options object, call options.add_argument(“–headless=new”), and pass it as webdriver.Chrome(options=options). Use headless mode for automated CI runs, but keep the visible browser while developing tests so you can see what the automation is actually doing.
Can these tests run automatically whenever code changes?
Yes. Once your tests live in a Git repository, add a GitHub Actions workflow file that installs Python and Selenium, runs pytest, and reports results on every push. This is the standard next step after your local suite is stable.
Fall Picks
fall essentials
As an affiliate, we earn on qualifying purchases.
