Are you having trouble with the SessionNotCreatedException error when trying to automate Microsoft Edge with Selenium? You're not alone! This error can be frustrating, but don't worry, there are a few steps you can take to fix it.
What is SessionNotCreatedException?
The SessionNotCreatedException error is thrown when Selenium is unable to create a new session with the web browser. This can happen for a variety of reasons, such as compatibility issues between the Selenium WebDriver and the browser, or problems with the browser's driver executable.
Checking Microsoft Edge Compatibility
The first step in fixing the SessionNotCreatedException error is to make sure that you are using a compatible version of Microsoft Edge and the Edge WebDriver. Selenium 4.0.0-alpha supports Microsoft Edge version 79 and above. If you are using an older version of Microsoft Edge, you will need to upgrade to a newer version in order to use Selenium.
To check which version of Microsoft Edge you are using, open the browser and go to edge://settings/help. This will display the current version of the browser.
To check which version of the Edge WebDriver you are using, open a command prompt and enter the following command:
edgedriver --version
This will display the version of the Edge WebDriver executable.
Downloading the Edge WebDriver
If you are using an older version of the Edge WebDriver, or if you don't have it installed, you will need to download the latest version from the Microsoft Edge WebDriver download page. Make sure to download the version that matches your operating system and version of Microsoft Edge.
Once you have downloaded the Edge WebDriver, extract the contents of the zip file to a folder on your computer. For example, you might extract the contents to a folder called C:\edgewebdriver.
Setting the Edge WebDriver Path
After you have downloaded and extracted the Edge WebDriver, you will need to set the path to the executable in your Selenium code. This can be done using the System.setProperty() method in Java, or the webdriver.edge.driver capability in other languages.
Here is an example of how to set the Edge WebDriver path in Java:
System.setProperty("webdriver.edge.driver", "C:\\edgewebdriver\\msedgedriver.exe");
WebDriver driver = new EdgeDriver();
Make sure to replace C:\\edgewebdriver\\msedgedriver.exe with the actual path to the Edge WebDriver executable on your computer.
Using the EdgeOptions Class
The EdgeOptions class is a special class in Selenium that allows you to set various options for the Edge browser, such as the path to the Edge WebDriver, or the location of the user data directory. Using the EdgeOptions class can help you avoid the SessionNotCreatedException error.
Here is an example of how to use the EdgeOptions class in Java:
EdgeOptions options = new EdgeOptions();
options.setBinary("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");
options.setCapability("useAutomationExtension", false);
System.setProperty("webdriver.edge.driver", "C:\\edgewebdriver\\msedgedriver.exe");
WebDriver driver = new EdgeDriver(options);
In this example, the setBinary() method is used to set the path to the Microsoft Edge executable, and the setCapability() method is used to disable the automation extension. These options can help you avoid the SessionNotCreatedException error.
The SessionNotCreatedException error can be frustrating, but it is usually easy to fix. By checking your version of Microsoft Edge and the Edge WebDriver, downloading the latest version of the Edge WebDriver, setting the path to the Edge WebDriver executable, and using the EdgeOptions class, you can avoid the SessionNotCreatedException error and successfully automate Microsoft Edge with Selenium.
References
| Title | Author | Date | URL |
|---|---|---|---|
| Microsoft Edge WebDriver | Microsoft | 2021-02-01 | https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ |
| EdgeOptions Class | Selenium | 2021-02-01 | https://www.selenium.dev/documentation/en/webdriver/webdriver_basics/working_with_different_browsers/#edgeoptions |