"SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81" - Solved!
Are you getting this frustrating error when trying to automate your Chrome browser using Selenium and ChromeDriver? This error message indicates an incompatibility issue between your ChromeDriver version and the version of Chrome installed on your machine. This article will guide you through understanding the problem and provide the solution to get your automation scripts running smoothly again.
The Problem: Mismatched Versions
The error "SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81" essentially tells you that the ChromeDriver you are using is specifically designed for Chrome version 81. If your Chrome browser is a different version, the two won't play nicely together.
Scenario and Code Example:
from selenium import webdriver
# Instantiate a ChromeDriver object
driver = webdriver.Chrome()
# Perform actions on the browser (e.g. navigating to a website)
driver.get("https://www.google.com")
# Close the browser
driver.quit()
In this example, you might get the error if you have a Chrome version other than 81 installed on your machine.
Understanding the Issue:
ChromeDriver, the software that allows Selenium to control Chrome, requires a specific compatibility with the Chrome browser version. This compatibility ensures proper communication and functionality.
Why does this happen?
Chrome and ChromeDriver are both rapidly evolving projects. Each new version of Chrome introduces updates, security patches, and potentially changes to the internal browser architecture. These changes may affect how ChromeDriver interacts with the browser, necessitating the creation of new ChromeDriver versions.
The Solution:
-
Check Chrome and ChromeDriver Versions:
- Chrome: Find your Chrome version by going to "Settings -> Help -> About Google Chrome".
- ChromeDriver: Check the version of ChromeDriver you have downloaded and installed. If you don't know, you can use the command
chromedriver --version
in your terminal.
-
Upgrade or Downgrade ChromeDriver:
-
Download the correct ChromeDriver: Visit the ChromeDriver Download Page and select the version compatible with your Chrome browser. Always make sure the version you download matches your Chrome version.
-
Replace Existing ChromeDriver: Replace the old ChromeDriver executable with the newly downloaded one in the location where your Selenium scripts expect to find it.
-
Additional Tips:
-
Use Selenium WebDriver Manager: The WebDriverManager library for Python automatically downloads and manages the appropriate ChromeDriver version for your Chrome installation, eliminating the need to manually update it. https://github.com/bonigarcia/webdrivermanager.
-
Keep ChromeDriver Updated: Regularly check for new ChromeDriver releases on the official website to ensure compatibility and support for the latest Chrome features.
-
Automate Version Management: Consider using tools like WebDriverManager or CI/CD pipelines that automatically update ChromeDriver to ensure compatibility with the Chrome browser used in your test environment.
Conclusion:
The "SessionNotCreatedException" error is usually a simple matter of mismatched versions between ChromeDriver and your Chrome browser. By following the steps outlined in this article, you can quickly identify and resolve the issue, enabling your Selenium scripts to run smoothly and efficiently. Remember to keep both ChromeDriver and Chrome updated to avoid encountering this error in the future.