Overview
Selenium 4.8, released on February 7, 2023, improves browser log inspection and network error handling.
Main Features
Log inspection
The log inspection API allows capturing console, network, and performance logs from the browser directly from the test.
python
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.set_capability('goog:loggingPrefs', {
'browser': 'ALL',
'performance': 'ALL',
})
driver = webdriver.Chrome(options=options)
driver.get('https://example.com')
# Retrieve browser logs
for log in driver.get_log('browser'):
print(f"{log['level']}: {log['message']}")
driver.quit()
Improved network handling
Network conditions can be simulated via the DevTools protocol, enabling testing of application behavior under slow connections or errors.
python
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get('https://example.com')
# Explicit wait for an element
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.TAG_NAME, 'h1'))
)
print(element.text)
driver.quit()
