October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk8 min

Using Selenium and Hypothesis in Python for Automated Browser Testing

Selenium drives the browser; Hypothesis explores generated inputs and action sequences. Learn when to use @given or state machines, how to wait for dynamic pages, and how to investigate failures.

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 Selenium WebDriver to operate a real browser and Hypothesis to generate inputs—or sequences of user actions—that exercise your application. Start with a normal Selenium test, add @given when a behavior should hold across many inputs, and use a state machine when the important bugs depend on action order. This is a practical combination of the two tools, not an integration officially documented by Selenium or Hypothesis.

What Selenium and Hypothesis each do

Selenium’s Python bindings let a test interact with a browser: navigate, locate elements, enter values, click controls, and inspect what the page displays. Hypothesis supplies generated values to ordinary Python tests through strategies and @given. Its stateful testing API can also choose a sequence of rules, such as adding and removing items, and check invariants as those actions occur.

Together, they let you test browser-visible properties beyond a few manually selected examples. Selenium does not generate the test data, and Hypothesis does not drive the browser; your test connects them by using generated values or actions in Selenium operations and asserting the expected result.

Set up the Python environment

The Selenium Python API documentation currently lists Python 3.10 or newer and support for Chrome, Edge, Firefox, Safari, WebKitGTK, WPEWebKit, and remote protocol use. Check the current Selenium Python API documentation against your chosen browser and environment, since compatibility details can change.

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.
  1. Create and activate a virtual environment using your project’s usual method.

  2. Install Selenium and Hypothesis:

    python -m pip install -U selenium hypothesis

    Selenium’s current Python documentation gives pip install -U selenium; Hypothesis’s quickstart gives pip install hypothesis.

  3. Install or configure a browser supported by your environment. Modern Selenium uses Selenium Manager for browser and driver installation on most supported platforms; you can also specify browser and driver details manually when your setup requires it.

  4. Run tests through pytest or unittest. Hypothesis-generated tests are ordinary Python functions and work with either framework.

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

The browser fixture, application URL, selectors, and cleanup process depend on your project. The examples below show test structure, not a complete fixture or a test verified against a live application.

Start with one conventional Selenium test

Before adding generated data, establish one important behavior with a known input. This confirms that the application, browser setup, selectors, and expected result make sense before Hypothesis multiplies the cases.

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

def test_search_shows_results(driver):
    driver.get("https://example.test/search")
    field = driver.find_element(By.NAME, "q")
    field.clear()
    field.send_keys("selenium")
    field.submit()

    WebDriverWait(driver, 10).until(
        EC.visibility_of_element_located((By.ID, "search-results"))
    )
    assert driver.find_element(By.ID, "search-results").is_displayed()

This assumes a test fixture named driver, a page at the example URL, a search field named q, and a results element with ID search-results. Replace those with elements and behavior that actually exist in a controlled application.

Use @given for properties over generated inputs

Choose an ordinary Hypothesis test when each example can begin from fresh application state and the property should hold for a useful range of independent values. For instance, if a search field should accept non-empty text and display a results region after submission, generate text and assert that visible invariant.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
from hypothesis import given, strategies as st
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

@given(st.text(min_size=1, max_size=40))
def test_search_input_is_accepted(driver, search_term):
    driver.get("https://example.test/search")
    field = driver.find_element(By.NAME, "q")
    field.clear()
    field.send_keys(search_term)
    field.submit()

    WebDriverWait(driver, 10).until(
        EC.visibility_of_element_located((By.ID, "search-results"))
    )
    assert driver.find_element(By.ID, "search-results").is_displayed()

This is an editorial example of how to connect the libraries, not a ready-to-run test or officially documented integration. It needs an application whose form accepts the generated values and whose selectors and expected behavior match the code. A property should be meaningful: asserting only that a form can be submitted may miss whether the app handles the value correctly.

Constrain strategies to valid, useful cases

The example uses st.text(min_size=1, max_size=40) to keep values within a plausible field range. Choose constraints from your application’s actual validation rules. If the app only accepts particular characters, formats, or lengths, encode those constraints in the strategy rather than letting most generated examples test rejection paths unintentionally.

Hypothesis’s quickstart documents 100 generated inputs by default and a max_examples setting for changing that count. More examples mean more browser work, so tune the count to the value of the property and the available test time rather than assuming that a larger count is always better.

Keep generated examples isolated

Each generated example should start from state that will not be contaminated by an earlier example. Navigate to a clean test route, reset server-side records, create unique test data, or use a project fixture that reliably establishes and tears down the needed state. Selenium and Hypothesis do not guarantee this isolation for you. Without it, one example’s data can change what a later example sees, making failures hard to understand.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

Use a state machine when action order matters

Use RuleBasedStateMachine when earlier actions affect which later actions are valid or what outcomes should follow. A cart, multi-step form, or editable list may need sequences such as add, remove, and submit—not just a collection of unrelated input values. Hypothesis stateful tests chain rules and can run invariants after steps; simpler cases may be clearer as ordinary @given tests.

A useful stateful browser test keeps a small expected model in Python alongside the browser. For example, after an “add item” action, update the model and check the visible cart count; after “remove item,” update the model again and check that the page agrees. Rules should represent meaningful user operations, while invariants express behavior that should remain true after each step.

Choose between generated inputs and generated action sequences

Question Ordinary @given State machine
What varies? Independent generated input values. Prior actions, the order of operations, and values used by rules.
What is the best fit? A property that should hold for many separate inputs. A behavior whose outcome depends on the sequence of operations.
What must the test explain? The expected result for each generated input. A simple model of state and invariants that can be checked as rules run.
What should you weigh? Whether each example is independent and the browser work per example is affordable. Whether the model and minimized action sequence remain understandable, and the browser work per sequence is affordable.

The distinction between independent generated tests and chained rules follows Hypothesis’s documentation. Runtime and model clarity are practical design considerations; there is no quantified performance comparison here.

Wait for page conditions instead of sleeping

Browser commands and page scripts do not necessarily finish at the same time. A page’s HTML assets loading does not guarantee that JavaScript-driven changes are ready. Selenium identifies these timing races as a common source of flaky tests and recommends condition-based explicit waits.

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

Wait for the state the next test action requires: for example, visibility before reading an element or clickability before clicking it. The example’s WebDriverWait polls for a particular condition and stops when it becomes true or the timeout is reached. A fixed time.sleep() can waste time when the page is fast and still be too short when it is slow.

Do not casually mix implicit and explicit waits. Selenium warns that combining them can produce unpredictable total wait durations. Prefer explicit waits around the specific asynchronous state your test depends on.

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
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Understand shrinking and replaying a failure

When Hypothesis finds a failing case, shrinking attempts to reduce it to a simpler example. For a stateful failure, the report can show a short, program-like sequence of actions. Preserve that output when filing a defect: a smaller reproducer is often easier to inspect than a long random run.

Hypothesis supports seed-based replay, including pytest’s --hypothesis-seed. A seed does not guarantee identical browser behavior if timing, external services, or other state is nondeterministic. Hypothesis’s settings documentation distinguishes seed replay from deterministic CI behavior; in browser tests, treat replay as a useful aid, not a promise of perfectly identical execution.

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.

Troubleshoot common failures

  • Browser or driver does not start: Check that the browser is installed and supported in the current environment, then consult the current Selenium Python API documentation for setup guidance. Selenium Manager handles installation on most supported platforms, but manual browser and driver configuration remains possible.

  • An element cannot be found immediately after navigation: The page may not yet have reached the state that creates the element. Wait for the specific condition, such as element visibility, instead of adding a fixed sleep.

  • A wait times out: Verify that the URL, locator, and expected condition match the actual application, and determine whether the page reached the intended state. An explicit wait timing out means its condition was not met within the configured time.

  • Waits take unexpectedly long: Look for implicit and explicit waits being used together; Selenium warns that their combined timing is unpredictable.

    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.
  • Generated examples fail validation: Narrow the strategy to inputs the property is meant to cover, or write a separate test for invalid-input behavior. Unconstrained data can spend most of the run exercising a different property.

  • Results change between examples: Reset browser and application state or isolate records so each generated example begins from a known baseline.

  • A failure does not recur with the same seed: Check for timing, external state, or other nondeterministic influences. Save the minimized failure report and the environment details rather than relying on seed replay alone.

Or skip the browser setup

For screenshot capture rather than interactive browser testing, ScreenshotNeo provides a one-request screenshot API. It is not a substitute for Selenium interactions or Hypothesis-generated assertions, but can remove the need to install and operate a browser just to capture a page image.

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

See the ScreenshotNeo API documentation for request options. Cookie and consent banners, newsletter popups, and chat widgets are removed before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. An MCP server provides screenshot tools for AI agents. The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots.

Sign up for 1,000 free screenshots a month, with no card required.

Sources

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

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.