Selenium
raw JSON → 4.41.0 verified Tue May 12 auth: no python install: verified quickstart: stale
Python bindings for Selenium WebDriver — browser automation for Chrome, Firefox, Edge, Safari. Current version is 4.41.0 (Feb 2026). Requires Python >=3.10. Selenium Manager (built-in since 4.6) automatically downloads and manages browser drivers — manual chromedriver management is no longer needed. All find_element_by_*() shorthand methods were removed in Selenium 4.
pip install selenium Common errors
error AttributeError: 'WebDriver' object has no attribute 'find_element_by_id' ↓
cause The `find_element_by_*` methods were deprecated and removed in Selenium 4, replaced by the more generic `find_element()` method using the `By` enum.
fix
Use
driver.find_element(By.ID, "element_id") after importing By from selenium.webdriver.common.by. error selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. ↓
cause Selenium WebDriver (version 4.41.0, which predates Selenium Manager being built-in) could not locate the browser driver executable (e.g., `chromedriver`) in your system's PATH.
fix
Ensure the driver executable is in your system's PATH, or provide its explicit path to the
Service object: from selenium.webdriver.chrome.service import Service; service = Service(executable_path='/path/to/chromedriver'); driver = webdriver.Chrome(service=service). error selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element ↓
cause The WebDriver failed to find an element on the webpage matching the provided locator, often due to an incorrect locator, or the element not being loaded or present on the page yet.
fix
Verify the locator (CSS selector, XPath, ID, etc.) is correct, and use explicit waits (
WebDriverWait) to wait for the element's presence or visibility before attempting to interact with it. error DeprecationWarning: executable_path has been deprecated, please pass in a Service object ↓
cause In Selenium 4, passing `executable_path` directly to the browser driver constructor (e.g., `webdriver.Chrome()`) is deprecated; a `Service` object should be used instead for configuring the driver.
fix
Instantiate a
Service object with the driver path and pass it to the browser driver constructor: from selenium.webdriver.chrome.service import Service; service = Service(executable_path='/path/to/chromedriver'); driver = webdriver.Chrome(service=service). Warnings
breaking All find_element_by_*() shorthand methods removed in Selenium 4. driver.find_element_by_id(), find_element_by_xpath(), find_element_by_css_selector(), find_elements_by_class_name() etc. all raise AttributeError. Still the most common LLM-generated Selenium footgun. ↓
fix Replace find_element_by_id('x') with find_element(By.ID, 'x'). Replace find_element_by_css_selector('.x') with find_element(By.CSS_SELECTOR, '.x'). Import: from selenium.webdriver.common.by import By
breaking Python 3.9 dropped in Selenium 4.33+. Now requires Python >=3.10. ↓
fix Pin selenium<4.33 for Python 3.9 environments.
breaking desired_capabilities parameter deprecated and removed from WebDriver constructors. Passing desired_capabilities= raises TypeError in modern Selenium 4. ↓
fix Use Options objects instead: options = ChromeOptions(); options.set_capability('key', 'value'). Pass options= to the WebDriver constructor.
breaking options.add_argument('--headless') (old Chrome headless) deprecated. Chrome switched to a new headless implementation — use --headless=new instead. ↓
fix Replace --headless with --headless=new in ChromeOptions. The new headless renders pages more like a real browser.
gotcha Selenium Manager automatically downloads matching browser drivers since 4.6. Manually downloading chromedriver and putting it on PATH is no longer necessary — but if you have a stale chromedriver on PATH, it may conflict with Selenium Manager. ↓
fix Remove manually downloaded chromedriver from PATH and let Selenium Manager handle it. Or pin a specific driver version via Service(executable_path='...').
gotcha Not using WebDriverWait causes flaky tests. Immediately calling find_element() after page navigation often fails because the element hasn't loaded yet. ↓
fix Always use WebDriverWait with expected_conditions: wait = WebDriverWait(driver, 10); element = wait.until(EC.presence_of_element_located((By.ID, 'element-id')))
gotcha driver.quit() must be called to close the browser process. Using driver.close() only closes the current window but leaves the browser process running. Always use try/finally or context manager. ↓
fix Use try/finally: try: ... finally: driver.quit(). Or use with statement with a context manager wrapper.
Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.01s 52.5M
3.10 slim (glibc) - - 0.01s 53M
3.11 alpine (musl) - - 0.04s 57.9M
3.11 slim (glibc) - - 0.03s 58M
3.12 alpine (musl) - - 0.03s 48.6M
3.12 slim (glibc) - - 0.02s 49M
3.13 alpine (musl) - - 0.03s 48.3M
3.13 slim (glibc) - - 0.02s 49M
3.9 alpine (musl) - - 0.41s 52.1M
3.9 slim (glibc) - - 0.39s 53M
Imports
- webdriver wrong
# Selenium 3 shorthand methods — removed in Selenium 4: driver.find_element_by_id('username') # AttributeError driver.find_element_by_css_selector('.item') # AttributeError driver.find_element_by_xpath('//button') # AttributeError driver.find_elements_by_class_name('item') # AttributeErrorcorrectfrom selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC # Selenium Manager handles chromedriver automatically driver = webdriver.Chrome() driver.get('https://example.com') # Correct element finding (Selenium 4) element = driver.find_element(By.ID, 'username') elements = driver.find_elements(By.CSS_SELECTOR, '.item') driver.quit()
Quickstart stale last tested: 2026-04-23
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
# Selenium Manager downloads chromedriver automatically
options = Options()
options.add_argument('--headless=new') # new headless mode
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(options=options)
try:
driver.get('https://example.com')
# Wait for element before interacting
wait = WebDriverWait(driver, timeout=10)
button = wait.until(
EC.element_to_be_clickable((By.ID, 'submit-btn'))
)
button.click()
# Find elements
items = driver.find_elements(By.CSS_SELECTOR, '.product-item')
print(f'Found {len(items)} items')
finally:
driver.quit()