How to Fix 'Session Not Created' Error in Selenium
session not created error in Selenium happens when the browser driver version does not match the installed browser version. To fix it, update your browser driver (like chromedriver) to the version compatible with your browser and ensure both are up to date.Why This Happens
This error occurs because Selenium tries to start a browser session using a driver that does not support the installed browser version. For example, if your Chrome browser updated but your chromedriver is old, Selenium cannot create a session.
from selenium import webdriver # Using old chromedriver with new Chrome browser driver = webdriver.Chrome(executable_path='path/to/old/chromedriver') driver.get('https://example.com')
The Fix
Update your browser driver to match your browser version. For Chrome, download the latest chromedriver from the official site that supports your Chrome version. Then, use the updated driver path in your Selenium code.
from selenium import webdriver from selenium.webdriver.chrome.service import Service service = Service('path/to/updated/chromedriver') driver = webdriver.Chrome(service=service) driver.get('https://example.com') print('Browser opened successfully') driver.quit()
Prevention
To avoid this error in the future, always keep your browser and driver versions in sync. Use tools or scripts to check driver compatibility automatically. Consider using WebDriver managers that download the correct driver version for you.
- Regularly update browsers and drivers.
- Use WebDriver manager libraries like
webdriver-managerin Python or Java. - Test driver compatibility after browser updates.
Related Errors
Other common errors include:
- Driver executable needs to be in PATH: Selenium cannot find the driver file.
- Timeout errors: Caused by slow browser startup or network issues.
- Version mismatch warnings: When driver and browser versions differ slightly.
Fixes usually involve setting correct driver paths, updating drivers, or increasing timeouts.