Why Use Splinter?¶
Splinter is a Python library used to write web browser automation scripts.
The project has two primary goals:
Provide a common, high-level API on top of existing browser automation tools such as Selenium. The API is an abstraction layer that is human-friendly and designed for easy, efficient scripting.
Provide built-in functionality to handle common pain points with browser automation.
Example¶
The following code will type text into an input element:
Written in Splinter:
from splinter import Browser
browser = Browser('chrome')
browser.visit('http://cowabunga.tubular.awesome')
element = browser.find_by_css('.username')
element.fill('Michaelangelo')
Written in Selenium:
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get('http://cowabunga.tubular.awesome')
element = driver.find_elements(by=By.CSS_SELECTOR, value='.username')
element.send_keys('Michaelangelo')
Splinter’s API provides a clean interface, but there’s more going on here:
from splinter import Browser
browser = Browser('chrome')
browser.visit('http://cowabunga.tubular.awesome')
element = browser.find_by_css('.username')
element.fill('Michaelangelo')
Under the hood, Splinter will wait for an element to be in a safe state for interaction. This prevents common errors where elements may be found before the web application is ready.
Splinter supports multiple web automation back-ends. You can use the same code for web browser testing with Selenium as the back-end and “headless” testing (no GUI) with zope.testbrowser as the backend.
Splinter has drivers for browser-based testing on:
For headless testing, Splinter has drivers for: