{"id":2279,"library":"seleniumbase","title":"SeleniumBase","description":"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.","status":"active","version":"4.47.9","language":"en","source_language":"en","source_url":"https://github.com/seleniumbase/SeleniumBase","tags":["web automation","testing","scraping","selenium","pytest","browser automation","e2e testing","headless browser"],"install":[{"cmd":"pip install seleniumbase","lang":"bash","label":"Install SeleniumBase"},{"cmd":"seleniumbase install chromedriver latest","lang":"bash","label":"Install latest ChromeDriver (recommended)"}],"dependencies":[{"reason":"Required Python version.","package":"python","version":">=3.9"},{"reason":"Core dependency for browser automation.","package":"selenium","optional":false},{"reason":"Integrated test runner framework, often used for organizing tests.","package":"pytest","optional":false},{"reason":"Optional dependency for generating Allure Reports. No longer bundled by default.","package":"allure-pytest","optional":true}],"imports":[{"note":"Import BaseCase directly from seleniumbase for class-based tests.","wrong":"from seleniumbase.fixtures.base_case import BaseCase","symbol":"BaseCase","correct":"from seleniumbase import BaseCase"},{"note":"Use the SB context manager for non-pytest script execution.","symbol":"SB","correct":"from seleniumbase import SB"},{"note":"For direct, low-level WebDriver access with SeleniumBase enhancements.","symbol":"Driver","correct":"from seleniumbase import Driver"}],"quickstart":{"code":"from seleniumbase import SB\n\nwith SB() as sb:\n    sb.open(\"https://seleniumbase.io/demo_page\")\n    sb.type(\"#myTextInput\", \"This is an automated test\")\n    sb.click(\"#myButton\")\n    sb.assert_text(\"Automation Practice\", \"h3\")\n    sb.highlight(\"#myButton\")\n    sb.sleep(1)\n    sb.assert_element(\"tbody#tbodyId\")\n    print(\"Test completed successfully!\")","lang":"python","description":"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."},"warnings":[{"fix":"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)`.","message":"SeleniumBase methods (`self.open()`, `sb.type()`, etc.) must be called within the `BaseCase` test class context (using `self`) or the `SB()` context manager instance. Calling them directly or outside this scope will result in errors like 'It looks like you are trying to call a SeleniumBase method from outside the scope of your test class's `self` object'.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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).","message":"Element detection can be less reliable in headless mode compared to visible browser mode, leading to 'Element Not Found' errors due to differences in page rendering or dynamic content loading. This is a common challenge with headless browser automation.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"Web scraping scripts using SeleniumBase can break unexpectedly if the target website's HTML structure, element selectors (CSS/XPath), or anti-bot mechanisms change. SeleniumBase's auto-waiting features mitigate flakiness but cannot prevent issues arising from fundamental site changes. Additionally, anti-bot services and CAPTCHAs (like reCAPTCHA) can still detect automation, especially after browser updates, even with stealth options.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If you use Allure Reports, manually install `allure-pytest` with `pip install allure-pytest`.","message":"As of recent versions (e.g., around v4.x), `allure-pytest` is no longer bundled with SeleniumBase and must be installed separately if you wish to generate Allure Reports.","severity":"breaking","affected_versions":">=4.0"},{"fix":"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()`.","message":"Overriding `setUp()` or `tearDown()` methods in a `BaseCase` subclass requires careful invocation of `super().setUp()` and `super().tearDown()` to ensure SeleniumBase's core setup and teardown functionalities (like browser initialization/quitting, screenshot capture) are not inadvertently bypassed or corrupted. Calling `super()` at the wrong point, or not at all, can lead to broken tests or resource leaks.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}