Skip to main content

Adds automatic waiting to common Selenium interactions.

Project description

selenium-autowait

selenium-autowait adds automatic waiting to common Selenium interactions.

After autowait is enabled, Selenium waits before calling:

Method Wait condition
WebDriver.find_element Until the element is found
WebElement.click Until the element is clickable
WebElement.send_keys Until the element is clickable
WebElement.clear Until the element is clickable

This is useful for tests where elements may appear, become enabled, or become clickable shortly after the page changes.

Table of contents

Installation

Install the base package from PyPI:

pip install selenium-autowait

Or with uv:

uv add selenium-autowait

The base package requires Python 3.11 or newer and depends on Selenium. Pytest support is optional.

To use the bundled pytest fixture, install the pytest extra:

pip install "selenium-autowait[pytest]"

Or with uv:

uv add "selenium-autowait[pytest]"

Usage

Autowait works by globally monkey-patching Selenium's WebDriver and WebElement classes. Enable it before the Selenium interactions that should wait automatically, and disable it when that behavior is no longer needed.

The default timeout is 10.0 seconds. To change it, pass timeout when enabling autowait:

from selenium_autowait import enable_autowait


enable_autowait(timeout=5.0)

Plain Python

Enable autowait before interacting with Selenium elements:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium_autowait import disable_autowait, enable_autowait


driver = webdriver.Chrome()
enable_autowait()

driver.get("https://example.com")
button = driver.find_element(By.ID, "submit")

# Will wait until the button is clickable.
button.click()
disable_autowait()
driver.quit()

unittest

Enable autowait once for the test class in setUpClass, then disable it in tearDownClass:

import unittest

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webdriver import WebDriver
from selenium_autowait import disable_autowait, enable_autowait


class SubmitTests(unittest.TestCase):
    driver: WebDriver

    @classmethod
    def setUpClass(cls) -> None:
        enable_autowait()
        cls.driver = webdriver.Chrome()

    @classmethod
    def tearDownClass(cls) -> None:
        cls.driver.quit()
        disable_autowait()

    def test_submit(self) -> None:
        self.driver.get("https://example.com")
        self.driver.find_element(By.ID, "submit").click()

pytest

If installed with the pytest extra, the package exposes an autowait fixture through pytest's plugin entry point. Use the fixture in tests that should wait automatically:

from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webdriver import WebDriver


def test_submit(driver: WebDriver, autowait: None) -> None:
    driver.get("https://example.com")
    driver.find_element(By.ID, "submit").click()

You can also define the fixture yourself if you prefer local control:

from collections.abc import Generator

import pytest

from selenium_autowait import disable_autowait, enable_autowait


@pytest.fixture
def autowait() -> Generator[None, None, None]:
    enable_autowait(timeout=10.0)
    yield
    disable_autowait()

To enable autowait once for the whole pytest session, define a session-scoped fixture in conftest.py:

from collections.abc import Generator

import pytest

from selenium_autowait import disable_autowait, enable_autowait


@pytest.fixture(scope="session", autouse=True)
def autowait_session() -> Generator[None, None, None]:
    enable_autowait(timeout=10.0)
    yield
    disable_autowait()

Analyze test results with Testinel

selenium-autowait helps reduce flaky Selenium failures caused by elements that are not ready yet. When failures still happen, Testinel can help you understand them faster.

Testinel is a web-based analytics platform for automated testing. It turns test runs, logs, and failures into actionable reports, helping teams identify recurring root causes, review historical stability trends, and navigate from high-level test health to exact failing tests and logs.

Testinel supports Python, pytest, Selenium, and Playwright-based test workflows.

Testing

Install the development dependencies with uv:

uv sync --group dev

Run the default test matrix with tox:

uv run tox

The tox matrix covers Python 3.11 through 3.15, pytest 8 and 9, the minimum supported pytest version, the minimum supported Selenium version, and the latest available Selenium version. The tests use Chrome through Selenium, so Chrome and WebDriver support must be available on the test machine.

To run a single environment:

uv run tox -e py314-pytest9-seleniumlatest

Before publishing a release, run:

uv run pytest
uv run ruff check .
uv run ty check .
uv build
uvx --from twine twine check dist/*

Notes

  • Autowait globally monkey-patches Selenium WebElement and WebDriver methods.
  • Call enable_autowait() once before using autowaited Selenium interactions.
  • Calling enable_autowait() more than once raises RuntimeError.
  • Calling disable_autowait() when autowait is not enabled raises RuntimeError.
  • Passing a non-positive timeout raises ValueError.
  • click, send_keys, and clear wait until the element is clickable before performing the original Selenium action.

Disclaimer

Selenium is a trademark of its respective owners. selenium-autowait is an independent third-party plugin for Selenium and is not affiliated with, endorsed by, or sponsored by the Selenium project or its maintainers. The Selenium name is used solely to describe compatibility with Selenium.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

selenium_autowait-0.1.0.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

selenium_autowait-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file selenium_autowait-0.1.0.tar.gz.

File metadata

  • Download URL: selenium_autowait-0.1.0.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for selenium_autowait-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b39167f34042c7cf83347f4e37bbf30911e693486df80ad669bad37ae323eacc
MD5 2a2913dc2d6a9e2784ca15129726dbbf
BLAKE2b-256 3587a07d52a0aedd575af7a2c208b5dcfc950e9de70c845e9b6b5403507405b4

See more details on using hashes here.

File details

Details for the file selenium_autowait-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: selenium_autowait-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for selenium_autowait-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 51083db43a0b540dbbd3745f5735e1fdcb3832ebec8526c8b3e4cc5a31375f04
MD5 03aba774f03d52d0b12ee82c158f2311
BLAKE2b-256 c86ca9c1fab732f9c0f2fa8a4533dad8bc290bdebb1e581779fda90f7d2a1b70

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page