Selenium is an open-source browser automation framework that enables programmatic control of web browsers across multiple platforms and languages. Originally created in 2004, it has evolved into the de facto standard for web application testing and automation, with Selenium WebDriver conforming to the W3C WebDriver specification since 2018. At its core, Selenium allows you to locate elements on a page, interact with them just as a user would, and verify behavior—making it indispensable for end-to-end testing, web scraping, and repetitive browser tasks. The key mental model: Selenium doesn't "see" the page like a human does; it navigates the DOM tree, so mastering locators and understanding how pages load asynchronously are essential to writing robust, non-flaky automation.
What This Cheat Sheet Covers
This topic spans 22 focused tables and 218 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: WebDriver Initialization and Setup
Every Selenium script begins by spinning up a driver for a specific browser, and getting this layer right removes the single most common source of early frustration—mismatched driver versions. Since Selenium 4.6, Selenium Manager handles driver downloads automatically, so most of these one-liners just work; the rest cover remote/Grid sessions and the cleanup calls (quit() vs close()) you should never forget in teardown.
| Method | Example | Description |
|---|---|---|
from selenium import webdriverdriver = webdriver.Chrome() | • Launches a Chrome browser instance • Selenium Manager auto-downloads the matching ChromeDriver since 4.6+. | |
driver = webdriver.Firefox() | • Launches Firefox using GeckoDriver • supports full Selenium features. | |
driver = webdriver.Edge() | • Launches Microsoft Edge (Chromium-based) • requires matching EdgeDriver version. | |
driver = webdriver.Safari() | • Launches Safari on macOS using built-in safaridriver • enable first with safaridriver --enable in terminal. | |
Automatic in Selenium 4.6+ | • Automatically downloads and manages browser drivers without manual setup • enabled by default in Selenium 4.6+. |