Selenium Webdriver is a powerful tool for automating web browsers, and it is widely used in testing and web scraping. However, the developers or testers often encounter SessionNotCreatedException. This article will discuss the causes of this error and provide some practical solutions to overcome it.
Table of contents
What is session not created exception?
The SessionNotCreatedException happens when Selenium WebDriver fails to create a new browser session. This error generally displays with the following message:
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not createdCode language: CSS (css)
This exception can occur for various reasons, often due to compatibility issues between different components of your Selenium setup. This means that WebDriver failed to establish a connection with the browser and create a new session for automated tests.
The SessionNotCreatedException is a critical error that stops the execution of your Selenium tests and further automated actions. It’s often one of the first issues that the dev team faces when setting up or updating their Selenium environment.
Common causes
The possible causes of the SessionNotCreatedException in Selenium usually happens for two reasons. First, the browser version might not match the WebDriver version, which can lead to compatibility issues. For example, if you’re using an outdated WebDriver with a new version of Selenium or if your Chrome browser version is too new or too old for the ChromeDriver you’re using, the session will not be created.
Second, Selenium might be unable to find or use the WebDriver properly due to an invalid remote server address, a wrong path to the WebDriver in your code, or an incomplete or broken WebDriver file.
There are a few other reasons this error can occur. Sometimes, your system info or computer’s security settings might prevent the WebDriver from running. Additionally, a mistake in setting up the WebDriver in your code or attempting to use new browser features with an outdated WebDriver can cause this issue. Lastly, the exception can occur if the browser or the WebDriver isn’t installed correctly.
Troubleshooting steps for session not created exception
Caused by old chrome driver version
Suppose we have a test class in which the Chrome driver version is very old and not compatible with the Chrome version installed on our system.
That results in this error:
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Code language: CSS (css)
To fix this, check your Google Chrome version at chrome://version.
Update your Selenium tests to use a matching version of ChromeDriver.
Otherwise, you can remove the line specifying an old version of ChromeDriver, allowing WebDriverManager to use the latest compatible version automatically.
After making these changes, clean and execute your project. These modifications should resolve the SessionNotCreatedException and help the test run successfully.
Caused by incorrect Chrome binary path
The incorrect binary path inside the Selenium tests could also cause SessionNotCreatedException.
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created:Code language: CSS (css)
To fix the SessionNotCreatedException, make sure you set the correct path to chromedriver using System.setProperty before creating the ChromeDriver object.
Also, check that the version of ChromeDriver matches your installed Chrome browser version and that any options you pass to the driver are correct. This will help avoid the error.
Final thoughts on session not created exception in Selenium
In conclusion, the SessionNotCreatedException is a well-known issue in Selenium projects and is typically caused by a mismatch between the Chrome browser and ChromeDriver versions. Ensuring that your Chrome browser and ChromeDriver are up-to-date and compatible is important. Verifying system info and keeping the latest version of all tools can help prevent this error. Regularly maintaining your Selenium project and addressing compatibility issues can ensure the smooth execution of automated tests without running into session creation problems. Happy testing!
Don’t miss these
Follow our blog
Be the first to know when we publish new content.
- How to find an element in Selenium - October 5, 2024
- Resolved: SessionNotCreatedException - October 2, 2024
- Katalon Recorder Automation Overview - September 12, 2024