Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk7 min

How to Troubleshoot Selenium Test Failures in pytest

A practical workflow for isolating Selenium failures in pytest, from startup and synchronization to locator, browser, and fixture problems.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start by rerunning only the failing pytest test and finding the first WebDriver command that fails. Then classify the failure as driver startup, synchronization or page state, locator or browsing context, browser-specific behavior, or fixture and test isolation. Fix that layer—not a later cleanup error or a passing run that merely hides the problem.

1. Reproduce the failure narrowly

Run the failing test by file, then narrow further to its test function. Pytest accepts selectors in the form path/to/test_file.py::test_function; add -v for verbose test names and -s when you need to see output written to the console.

pytest -v path/to/test_file.py::test_function -s

Use the selector and options that fit your project’s pytest configuration. Save the full traceback and note the first failing WebDriver command. A teardown exception can appear after the test body has already failed, so do not assume the last exception in the output is the original cause.

Record the test name, Selenium and Python versions, browser and version, whether the test uses local or remote WebDriver, and whether the failure repeats when run alone. A single pass after a failure does not establish that the cause is fixed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

2. Identify which stage failed

Separate session creation from commands issued after the browser starts. The stage narrows the likely causes and determines what evidence to collect.

Failure stage or symptom What to check first
Driver creation or session startup Browser installation, driver discovery, browser/driver compatibility, permissions, and whether failure occurs before the first navigation.
NoSuchElementException Locator correctness, current browsing context, and whether the application has rendered the expected state.
Element exists but interaction fails Whether it is visible and interactable, and whether the next action is waiting for the right condition.
TimeoutException Whether the chosen condition ever became true; recheck the locator, page state, context, and application outcome.
Only one browser fails Compare browser and driver versions and behavior, then verify the fix in the browser and environment that originally failed.
Fails only in the suite or after another test Shared browser state, fixture scope, test dependencies, cleanup, and whether the test passes with a fresh driver.

3. Fix synchronization and page-state races

A successful navigation call does not guarantee that JavaScript-created content or a post-click state is ready for the next command. Selenium identifies poor synchronization as its most common Selenium-related error source. An element may be absent because the locator is wrong, but it may also not have been rendered yet.

Wait for the condition the next command needs

Use an explicit wait for the actual condition: presence when the element must exist, visibility when it must be seen, or clickability when the next step is a click. For example, this waits up to ten seconds for an element with ID result to become visible:

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

result = WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located((By.ID, "result"))
)

Choose a timeout appropriate to the application and test environment; Selenium’s code examples are not a universal timeout recommendation. Presence alone is not enough when the element must be visible or clickable. For a click, for example, wait for the locator to be clickable rather than waiting an arbitrary number of seconds.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use sleeps only as a diagnostic experiment

A temporary longer time.sleep() that makes a failing test pass suggests a timing issue. It is not a robust final fix: it can still be too short on a slower run and wastes time when the page is ready sooner. Replace the experiment with a condition-based wait that describes what the test needs.

Avoid casually mixing implicit and explicit waits in the same session. Selenium warns that doing so can make the total wait duration unpredictable.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

4. Check the locator and browsing context

When an element cannot be found, verify the locator against the page state at the instant the failing command runs. Also check that WebDriver is looking in the right place: a test may need to switch to the intended frame or window before locating an element. If the target appears after an interaction or asynchronous update, wait for that state rather than retrying an unverified locator.

  • Confirm that the locator identifies the intended element in the current page state.
  • Check whether the page has navigated, opened a new window, or placed the target in a frame.
  • Distinguish “not in the DOM” from “in the DOM but not visible” and “visible but not ready for this interaction.”
  • For a timeout, inspect whether the application reached the expected state at all; a wait cannot make a failed page action succeed.

5. Diagnose browser and driver startup

Driver startup failures happen before the test can exercise the page, so treat them separately from element and assertion failures. Current Selenium Python documentation describes Selenium Manager as handling browser and driver installation in supported configurations when a WebDriver is instantiated. Manual browser or driver configuration remains an option when automatic management does not fit the environment.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check that the browser is installed and available to the test process, that the environment permits driver discovery or download as applicable, and that permissions and version compatibility are appropriate. Do not assume older setup instructions requiring every user to download a matching driver apply unchanged to modern Selenium.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

If a command fails only in one supported browser, compare the same test behavior in another supported browser as a diagnostic—not as proof that the original problem is solved. Return to the failing browser and environment to confirm the fix.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

6. Make pytest fixtures own the browser lifecycle

A driver fixture should make browser ownership and cleanup explicit. A simple function-scoped fixture creates a fresh driver for the test, yields it, and calls quit() even if the test raises an exception:

import pytest
from selenium import webdriver

@pytest.fixture
def driver():
    browser = webdriver.Chrome()
    try:
        yield browser
    finally:
        browser.quit()

This example assumes Chrome is available to Selenium in the test environment; choose the browser your project actually runs. Selenium’s Python testing guide documents a driver fixture and fresh-driver lifecycle patterns. The guide is on the project’s mutable trunk branch and describes Selenium’s own test setup, so its project-specific commands and configuration are not universal instructions for application repositories.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

If a shared driver is intentional, define the fixture scope and state-reset behavior deliberately. When failures depend on test order, compare an isolated run with a fresh-driver run and check whether earlier tests leave behind cookies, windows, navigation state, or other shared state.

7. Preserve evidence and verify the fix

Keep enough detail to distinguish a real fix from a lucky pass:

  • The exact pytest selector and complete traceback.
  • The first failing WebDriver command and whether it occurred during startup, the test body, or teardown.
  • Selenium, Python, browser, and driver details, plus local versus remote execution.
  • Whether it reproduces when run alone, in the suite, and across supported browsers.
  • The page state and wait condition immediately before the failure.

Selenium’s troubleshooting guidance also points to command logging as a way to investigate WebDriver activity. After changing code or environment, rerun the narrow reproduction and then the relevant suite. A cross-browser comparison helps isolate a browser-specific issue; it does not replace verification in the originally failing setup.

8. Troubleshooting checklist

  • Session does not start: check browser availability, driver handling, permissions, and compatibility before changing test waits.
  • Element is missing: confirm locator and context, then wait for the state that creates the element.
  • Element is found but cannot be used: wait for visibility or clickability as appropriate; DOM presence alone is not readiness.
  • Wait times out: verify that the application reached the expected state and that the locator and condition describe it correctly.
  • Test is flaky: use a temporary sleep only to test the timing hypothesis, then replace it with an explicit wait.
  • Only suite runs fail: inspect fixture scope, shared state, dependencies, and cleanup; compare with an isolated fresh-driver run.
  • Only one browser fails: compare browser-specific behavior and versions, then retest the fix in that browser.

Or skip the browser setup

If you need a screenshot artifact for a URL rather than an interactive Selenium test, ScreenshotNeo provides a one-request screenshot API. It does not replace pytest or prove that your application’s interactions work. Its API can return PNG, JPEG, WebP, or PDF; see the ScreenshotNeo documentation for options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo removes supported cookie banners, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.