Overview

Selenium 4.0, released on October 14, 2021, is a major release with Selenium Manager, relative locators, and full W3C WebDriver compliance.

Main Features

Selenium Manager and W3C

Selenium Manager automatically downloads browser drivers, eliminating manual configuration. The W3C WebDriver protocol replaces the old JSON Wire protocol.

python
from selenium import webdriver

# Selenium 4: no need to download the driver
# Selenium Manager does it automatically
driver = webdriver.Chrome()

driver.get('https://example.com')
print(f'Title: {driver.title}')

# Native W3C protocol
print(f'Capabilities: {driver.capabilities["browserName"]}')
driver.quit()

Relative locators

Relative locators find elements relative to other page elements: above, below, to the left, to the right, or nearby.

python
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.relative_locator import locate_with

# driver = webdriver.Chrome()
# driver.get('https://example.com/form')

# Relative locators
# email_label = driver.find_element(By.ID, 'email-label')
# email_input = driver.find_element(
#     locate_with(By.TAG_NAME, 'input').to_right_of(email_label)
# )

# Other relative locators:
# locate_with(...).above(element)
# locate_with(...).below(element)
# locate_with(...).near(element)
print('Relative locators available in Selenium 4')

Sources