Splinter

0.21.0 · active · verified Thu Apr 16

Splinter is a Python library that provides a high-level browser abstraction for web acceptance testing and browser automation. It supports multiple drivers including Selenium (for Chrome, Firefox, Edge, etc.) and offers a consistent API to interact with web elements, forms, and pages. It is actively maintained with regular feature releases and bug fixes, typically every few months. The current stable version is 0.21.0.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a headless Chrome browser, navigate to a URL, fill out a login form, click a button, and assert text presence. It includes error handling and ensures the browser is closed properly. For Chrome/Firefox, ensure the respective driver (e.g., chromedriver, geckodriver) is in your system's PATH or managed by a tool like `webdriver-manager`.

from splinter import Browser
import os

# Optional: Use webdriver-manager to automatically download/manage drivers
# from webdriver_manager.chrome import ChromeDriverManager
# driver_path = ChromeDriverManager().install()

# Create a Browser instance
# Common options: 'chrome', 'firefox', 'edge'
# headless=True is recommended for CI/CD or background tasks
browser = Browser('chrome', headless=True) # Or 'firefox', 'edge', etc.

try:
    browser.visit('http://quotes.toscrape.com/login')

    print(f"Visiting: {browser.url}")
    browser.fill('username', 'admin')
    browser.fill('password', 'password')
    browser.find_by_css('input[type="submit"]').click()

    if browser.is_text_present('Logged in!'):
        print(f"Successfully logged in. Current URL: {browser.url}")
        browser.click_link_by_text('Logout')
        assert browser.is_text_present('Login')
        print("Successfully logged out.")
    else:
        print("Login failed.")

except Exception as e:
    print(f"An error occurred during the test: {e}")
finally:
    if browser:
        browser.quit() # Always close the browser

view raw JSON →