Skip to content

Browserist Compared to Selenium#

Browserist is an extension to the Selenium that makes web scraping and browser automation even easier. Since Browserist only uses XPath expressions to target web elements, be aware of the differences in syntax.

Examples of Syntax Differences#

Get Element by ID#

browser.get.element("//*[@id='lname']")
driver.find_element(By.ID, "lname")
# Browserist with XPath:
browser.get.element("//*[@id='lname']")

# Selenium:
driver.find_element(By.ID, "lname")

Get Element by Class#

browser.get.element("//*[@class='information']")
driver.find_element(By.CLASS_NAME, "information")
# Browserist with XPath:
browser.get.element("//*[@class='information']")

# Selenium:
driver.find_element(By.CLASS_NAME, "information")

Get Element by XPath#

browser.get.element("//div[@class='information']")
driver.find_element(By.XPATH, "//div[@class='information']")
# Browserist with XPath:
browser.get.element("//div[@class='information']")

# Selenium:
driver.find_element(By.XPATH, "//div[@class='information']")

Why Use XPath?#

While Selenium offers several methods to target web elements – for instance By.ID, By.CLASS_NAME, etc. – Browserist solely uses XPath to locate web elements in the DOM of a web page. Why so?

XPath is a simple, yet powerful tool similar to a Swiss Army knife that gets the job done with compact code. And so you only need to master a single vocabulary instead of multiple By class options and importing extra modules from Selenium.