October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk7 min

How to Use Selenium with Python and nose2

A practical guide to running Selenium browser tests with Python and nose2, including installation, test discovery, waits, driver setup, and troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install Selenium and nose2 in the same Python environment, write browser checks as discoverable Python tests, and run nose2 from your project directory. Selenium drives the browser; nose2 finds and runs the tests. The guide below shows a minimal setup, reliable waits, discovery options, and common fixes.

What Selenium and nose2 each do

Selenium’s WebDriver is a language-neutral interface and protocol for controlling a browser. The Selenium Python bindings let Python code open pages, locate elements, and interact with them. nose2 is a test runner based on Python’s unittest; it discovers tests, runs them, and reports results. Selenium documentation · nose2 documentation

In practice, Selenium performs browser actions and exposes browser state, while nose2 decides which tests to run. nose2 is not a Selenium plugin that drives the browser, and Selenium does not discover your test files.

Install the packages in a project environment

A virtual environment keeps test dependencies separate from other Python projects. From the project directory, create and activate one using the command for your operating system and shell, then install both packages:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
python -m venv .venv
# Activate .venv using the command for your OS and shell.
python -m pip install -U selenium nose2

The nose2 getting-started guide documents pip install nose2; Selenium’s Python API documentation documents pip install -U selenium and recommends considering a virtual environment. Check your project’s Python, browser, and package compatibility before pinning versions. The nose2 documentation index lists version 0.16.0, released 2026-03-01; Selenium’s Python API documentation identified 4.49.0 as its latest release when checked on 2026-10-03. Those release identifiers can change.

Write a test nose2 will discover

By default, nose2 looks for Python modules whose filenames begin with test, then loads recognized test functions and unittest.TestCase test methods whose names begin with test. A file named test_example.py follows the default filename pattern; example_test.py does not.

Save this as test_example.py in your project’s test directory:

import unittest

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait


class TestExamplePage(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()

    def tearDown(self):
        if hasattr(self, "driver"):
            self.driver.quit()

    def test_page_has_heading(self):
        self.driver.get("https://example.com")
        heading = WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located((By.TAG_NAME, "h1"))
        )
        self.assertTrue(heading.text)

This is an illustrative pattern, not a claim about a live page’s contents. setUp starts a browser for each test, and tearDown closes it so a passing or failing test does not leave the session running. For a larger suite, consider sharing setup only when doing so does not make tests depend on one another.

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

Run the suite and control discovery

Run default discovery

From the project directory, run:

nose2

If the command is not on your shell’s PATH, run the module through the active Python environment:

python -m nose2

Keep the environment activated so nose2 and Selenium are imported from the same place where they were installed.

Set the test directory or import root

If the default search does not match your repository structure, supply a start directory and, when needed, the top-level import directory:

nose2 -s tests -t .

-s (or --start-dir) tells nose2 where discovery begins. -t (or --top-level-directory) sets the importable project root. Adjust these paths to your layout; for example, if tests live under src/project/tests, use that as the start directory and choose the directory that makes your project imports resolve as the top level.

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

Run one test by dotted name

nose2 also accepts dotted names to select a test module, class, or individual test. For example, with test_example.py in the importable test directory, run:

nose2 test_example.TestExamplePage.test_page_has_heading

The exact dotted name depends on the module’s import path from the configured top-level directory.

Configure discovery in a file

nose2 can read configuration from files such as unittest.cfg or nose2.cfg. The configuration can set discovery-related values such as the start directory, code directories, file patterns, and plugins. Use command-line options for a quick one-off run and a configuration file when the same layout applies consistently across local and automated runs. nose2’s discovery and loading are plugin-based; using --no-plugins disables the normal discovery and loading behavior, so it is not a general fix for tests that are not being found.

Wait for browser state, not an arbitrary delay

A successful navigation call does not mean JavaScript-driven content is ready for the next action. An explicit wait polls for a named condition at the point the test needs it. The example waits up to ten seconds for an h1 element to be present; the wait can return sooner when the condition becomes true, or raise a timeout if it does not.

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

Implicit waits instead affect element lookups by polling for elements that are not immediately available. Mixing implicit and explicit waits can make timing harder to reason about. A fixed time.sleep always delays for its full duration and can still be too short when a page is slow. Prefer a condition that represents the state under test, such as presence, visibility, or clickability. Selenium’s waits guide describes these patterns; because that Python guide is older, check its exact imports and behavior against the Selenium version installed in your project. Selenium waits documentation

Choose local execution or Selenium Grid

A local WebDriver session is the simplest place to develop a test: it controls a browser available in the same environment. Selenium Grid is the project’s documented route for scaling execution across remote browser environments. Grid can expand where and in which browser configuration tests run, but it adds setup and operational requirements. Start locally while debugging test logic; consider Grid when the suite needs remote or broader browser execution. Selenium’s documentation identifies Grid as the scaling path but does not establish a particular hosted provider or price. Selenium documentation

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

Do you still need to install a browser driver manually?

For modern Selenium versions, Selenium Manager generally handles driver setup for supported browsers and platforms, so manual driver downloads and PATH configuration are not usually needed. This depends on the browser and platform being supported and correctly installed. If startup fails, check the browser installation, Selenium version, and the specific error before following older tutorials that prescribe manual driver downloads. Selenium Manager documentation

Troubleshoot common failures

  • nose2 reports no tests found: Check that the file begins with test, the test method or function begins with test, and you ran nose2 from the intended project directory. Try nose2 -s tests -t . with paths matching your layout.
  • Import errors for Selenium or nose2: Activate the project environment and install both packages with that environment’s Python using python -m pip install -U selenium nose2. Confirm that python and nose2 resolve to the environment you expect.
  • Browser session fails to start: Verify the browser is installed and supported by your Selenium version and platform. Modern Selenium generally uses Selenium Manager; manual driver setup may still be needed in unsupported or constrained environments, but first inspect the actual startup error rather than assuming a missing PATH entry.
  • Element lookup raises a no-such-element error: The locator may not match, or the element may not exist yet. Verify the selector in the current page state and wait for the relevant condition before interacting.
  • An explicit wait times out: The condition did not become true before its maximum wait. Check whether navigation reached the expected page, the locator is correct, or the element is inside a frame or otherwise unavailable in the current context.
  • Tests leave browsers open: Ensure cleanup runs after failures. Keep browser shutdown in tearDown or use a cleanup strategy that is guaranteed to execute when test assertions fail.
  • Tests pass individually but fail in a suite: Look for shared browser state, cookies, data, or order-dependent assumptions. Isolate test setup and cleanup so each test starts from a known state.

Or skip the browser setup

If your task is to capture a page rather than interact with it or assert behavior, ScreenshotNeo can return a screenshot or PDF from one GET request. It accepts cookie or consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and billing status. It also provides an MCP server with take_screenshot, get_page_info, and capture_pdf tools for AI agents and other MCP clients. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. See the ScreenshotNeo API documentation.

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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

This captures a screenshot; it does not replace Selenium when a test needs to click controls, inspect changing application state, or verify behavior. Learn about ScreenshotNeo or sign up for 1,000 free screenshots a month with no card.

Frequently Asked Questions

Does nose2 replace unittest?

No. nose2 is based on unittest and adds discovery, running, and plugin support; unittest provides the test case structure used in the example.

Can nose2 run Selenium tests without opening a browser?

A normal Selenium WebDriver test controls a browser session. A screenshot API can capture a page without a test-controlled browser, but it does not perform the interactions or assertions of a Selenium test.

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.

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

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.