Turn your manual testers into automation experts! Request a DemoStart testRigor Free

SessionNotCreatedException in Selenium: How to Resolve?

Selenium has stayed synonymous with automation testing for a long. Test scripting in Selenium gets caught up with many types of exceptions.

org.openqa.selenium.SessionNotCreatedException: session not created exception is one that happens explicitly when there is a mismatch or compatibility issue between the browser and WebDriver versions.

When Selenium cannot start a new browser session, SessionNotCreatedException is thrown. In this article, let us look into this exception’s reasons and possible resolution.

Reasons for SessionNotCreatedException in Selenium

  • Browser and WebDriver Versions are Incompatible
    This is the most common cause of SessionNotCreatedException in Selenium. For example, the browser version for Chrome and Firefox is incompatible with their corresponding WebDrivers like ChromeDriver and GeckoDriver.

    Example: You have updated the Chrome browser to version 114 during the latest version update but missed updating the ChromeDriver version and using version 112.

  • WebDriver Path is Incorrect
    If you have incorrectly set the WebDriver executable path in the Selenium script, this exception will be thrown. Selenium cannot interact with the WebDriver and cannot start the session.

    Example: You have set the path to ChromeDriver as C:\Drivers\ChromeDriver.exe in your Selenium script, but the actual path where ChromeDriver is located is C:\SeleniumDrivers\ChromeDriver.exe. This discrepancy can result in a SessionNotCreatedException.

  • Browser or WebDriver Installation is Corrupted
    If your browser and WebDriver installation are not complete/corrupted, then Selenium may not create a new session.

    Example: The ChromeDriver executable wasn’t completely downloaded due to a network issue.

  • Restrictive WebDriver Permission

    Sometimes, WebDriver might not have the necessary permissions to execute due to security settings.

    Example: You downloaded GeckoDriver from the internet on a Windows machine, then tried to run it without administrative rights. This might cause the exception because Selenium cannot start a new session.

  • Error in WebDriver Initialization
    This exception may occur if you have not initialized the WebDriver with the required capabilities in your Selenium script.
    Example: Incorrectly trying to set an option that doesn’t exist or is wrongly formatted in ChromeOptions().
    Another example is when your code looks like below, where you have created a driver instance before setting up the property:
    WebDriver driver = new ChromeDriver();
    System.setProperty ("webdriver.chrome.driver", "C:\\driver\\chromedriver.exe");
    You have to setProperty first and then create a driver instance next to resolve the exception.
    System.setProperty("webdriver.chrome.driver", "C:\\driver\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
  • Unsupported Browser Features
    An exception occurs when trying to run a browser feature in an older version that does not support that feature.

    Example: You are using Selenium to automate web application tests that utilize a very recent HTML5 feature, such as ‘Web Bluetooth API’ on Chrome version 70. Here, the exception occurs because the Chrome browser can not process the feature correctly.

How to Resolve SessionNotCreatedException?

Resolutions for SessionNotCreateException are as follows:

  • Check the Compatibility of the Browser and WebDriver: Browsers get frequent updates, so make sure the updated version is compatible with the existing WebDriver version. For example, you can download the latest ChromeDriver from the official website. Download the GeckoDriver from the GitHub repository.
  • Correct the Path to WebDriver: Check that the path specified for the WebDriver is correct or the WebDriver executable is present in the specified path. If not, correct the path. Also, check if the path to the WebDriver is added to your system’s PATH environment variable. If not, add it manually.
  • Re-download WebDriver: If there were issues with the WebDriver download and it got corrupted. Then, re-download and install the WebDriver executable to resolve the exception.
  • Provide the Permissions: The exception occurs when WebDriver lacks the required running permissions. Change the permission for WebDriver so that it can run properly. On Unix systems, this might involve using chmod to make it executable.
  • Correct WebDriver Initialization: Use the required accurate capabilities during the WebDriver initialization.
  • Use WebDrivermanager: By using WebDriverManager in your Selenium project, you can automatically manage the WebDriver binaries. Add the WebDriverManager dependency to your project and use it to set up the WebDriver.
  • Restart Your System: In some cases, simply restarting your computer can resolve the exception, especially after you have installed updates. In some cases, memory overuse occurs, and Selenium fails to open a session. In such cases, the system restart works well.
  • Check for Other Errors: Sometimes, SessionNotCreatedException can be caused by other underlying issues in your Selenium setup or script. Review the complete error message and stack trace for any additional clues.
  • Seek Help on Forums: If you still face issues, consider seeking help on forums like Stack Overflow. Provide details about your browser version, WebDriver version, and the error message you are encountering, and the community will help.

How can Generative AI and NLP Help?

When Artificial Intelligence is transforming every domain and industry, test automation is no exception. If you are using the Selenium framework for testing activities, use AI to transform your existing Selenium framework.

The plethora of Selenium exceptions and other disadvantages have caused organizations to seek better alternatives. Here are the 11 reasons why not to use Selenium for automation testing.

A more straightforward and optimized solution is using intelligent AI-powered test automation tools such as testRigor. It is a codeless testing tool where you can write your test cases in plain English. testRigor’s NLP-based capabilities let you write your test cases quickly without prior programming language knowledge. Everyone on your team can write and execute test cases. How liberating it is!

With testRigor, you need not identify UI elements with XPath/CSS paths. Just use the UI element text that you see on the UI. Here is an example:
enter "TV" into "Search"
enter enter
click "TV"
click "Add To Cart"
check that page contains "Item Added To Cart"

As you can see, writing test cases in testRigor is super easy and quick through its generative AI capabilities. You can also use the recorder to record your UI actions, and testRigor generates test cases in plain English.

Easily integrate testRigor into your existing testing workflow, as testRigor supports integrations with all significant test management, test reporting, ERP, CRM, and infrastructure providers.

Conclusion

You can resolve Selenium SessionNotCreatedException by addressing compatibility issues between the browser and the WebDriver, correcting configuration mistakes, or updating your testing environment.

However, if you want to bypass all these configuration overheads and focus on creating robust tests, use intelligent tools such as testRigor instead. Where you need not worry about the configurations and updates, testRigor handles all cross-browser, cross-platform, API, web, mobile, and desktop testing singlehandedly.

Join the next wave of functional testing now.
A testRigor specialist will walk you through our platform with a custom demo.
Related Articles

SAP Concur Testing

Concur Technologies, now SAP Concur, is an American software-as-a-service (SaaS) company providing travel and expense management ...

Authorize.net Testing

You need a payment gateway in several scenarios, especially when you are running a business that requires secure, efficient, and ...

KYC Portal CLM Testing

KYC Portal CLM is an award-winning Client Lifecycle Management (CLM) platform designed to streamline and automate the Know Your ...