Skip to content

Latest version Python 3.10 | 3.11 | 3.12+ Apache 2.0 license Codecov CodeQL Test Downloads

Browserist – Python Extension for Selenium 👨‍💻#

Introduction#

browserist 1. The belief that web browsers account for differences in websites or web applications in all of their ability and that a particular web browser is superior to others. 2. Discrimination or prejudice based on web browser.

Despite the urban definition, Browserist is a Python extension of the Selenium web driver that makes it even easier to use different browsers for testing and automation.

Main Features#

With Browserist as an extension to Selenium, you get:

✅ Improved stability and speed

✅ Simple syntax and less code

✅ Hassle-free setup across browsers: Chrome, Firefox, Edge, Safari, Internet Explorer

✅ Extensive framework of functions that makes browser automation easy

✅ Efficient development workflow with IntelliSense and type hints

Ready to try? Let's get started.

Difference from Selenium#

Improved Stability and Less Code#

Browserist improves stability with less code compared to standard use of Selenium. As browsers need time to render web pages, especially single-page applications, Selenium is often used with explicit timeouts:

With Selenium
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()

driver.get("https://example.com")
driver.implicitly_wait(3)
search_box = driver.find_element(By.XPATH, "//xpath/to/input")
search_button = driver.find_element(By.XPATH, "//xpath/to/button")
search_box.send_keys("Lorem ipsum")
search_button.click()
driver.quit()

Browserist does the same with less and cleaner code, yet also with increased stability and without explicit/implicit waits:

With Browserist
1
2
3
4
5
6
from browserist import Browser

with Browser() as browser:
    browser.open.url("https://example.com")
    browser.input.value("//xpath/to/input", "Lorem ipsum")
    browser.click.button("//xpath/to/button")

Why Avoid Explicit or Implicit Waits?#

As you can't click a button that's not ready in the DOM, Browserist simply checks if elements are ready before interacting with them. This makes the code more stable and less prone to errors.

Sweet Spot of Browser Automation#

You don't want to be too fast nor too slow when automating a browser. You're simply dependant on too many factors that are beyond your control: internet speed, server response time, etc. The sweet spot is to be just right:

Timing Consequence Code Description
Too short Code breaks time.sleep(1) Wait for 1 second, hoping that an element is ready within a fixed amount of time.
Just right Stable and fast wait.for_element() Browserist checks if an element is ready before interacting with it.
Too long Slow time.sleep(10) Wait for 10 seconds, just to be sure an element is ready.

Ready to try? Let's get started.