SeleniumBase is a complete web automation framework for end-to-end testing, built on top of the Selenium/WebDriver APIs. It simplifies browser automation with an intuitive syntax, built-in features for reliable interactions, and advanced capabilities like bot-detection avoidance. It supports various tasks from testing to web scraping and maintains a rapid release cadence with frequent patches.
pip install seleniumbaseVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates a basic interaction with a demo page using the `SB()` context manager. It opens a URL, types text into an input field, clicks a button, asserts text presence, highlights an element, and then asserts the presence of another element. This format allows running SeleniumBase scripts without explicit pytest integration.
Ensure all SeleniumBase methods are invoked via the `self` object within a `BaseCase` inheriting class or an `SB()` context manager instance. For example, `self.open(url)` or `sb.open(url)`.
Explicitly set the browser window size using `sb.set_window_size(width, height)` to simulate a real viewport, and consider adjusting user-agent strings to mimic real user behavior (`--user-agent="..."` command-line option).
Regularly verify and update selectors. Employ robust error handling and retry mechanisms. For anti-bot issues, experiment with `--uc` (undetected-chromedriver) mode, `--user-agent` rotation, and other stealth options, but be aware that detection is an ongoing cat-and-mouse game. Consider using proxy integration for IP rotation.
If you use Allure Reports, manually install `allure-pytest` with `pip install allure-pytest`.
When customizing `setUp()`/`tearDown()`, always call `super().setUp()` early in your `setUp()` method and `super().tearDown()` late in your `tearDown()` method to preserve SeleniumBase's default behavior. For example: `super().setUp()` then your custom code, and then your custom teardown code then `super().tearDown()`.
Run `pip install seleniumbase` in your terminal to install the library.
Run `seleniumbase install chromedriver` in your terminal to let SeleniumBase manage the driver, or manually place the driver executable in a directory that is part of your system's PATH.
Verify the element's locator using browser developer tools, ensure there is a sufficient wait time (e.g., `self.wait_for_element()` or `self.assert_element()`) before attempting to interact with the element, or re-evaluate the navigation flow.
Update your import statement to `from seleniumbase.sb_test_case import BaseCase`.