What driver do I have to use to run a selenium test in c # on the Edge Chromium browser?

Viewed 5073

I'm trying to launch a simple selenium test in c # with the Edge browser, but I can't. The error that indicates me is the following:

OpenQA.Selenium.DriverServiceNotFoundException: 'The file C: \ Selenium \ Drivers \ MicrosoftWebDriver.exe does not exist. The driver can be downloaded at http://go.microsoft.com/fwlink/?LinkId=619687

This is the line of code that gives me the error: driver = new EdgeDriver ("C:\\Selenium\\Drivers");

In the path C: \ Selenium \ Drivers I have the following driver: msedgedriver.exe

Downloaded from the page: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/

That driver corresponds to the version I have of the Edge: Microsoft Edge is up to date. Version 80.0.361.62 (Official compilation) (64 bits)

What am I doing wrong? What is my error? how do I solve it?

Thanks

5 Answers

At the time of writing, the Edgedriver downloaded by the nuget package Selenium.WebDriver.MSEdgeDriver is msedgedriver.exe, but the EdgeDriver(...) constructor is looking for MicrosoftWebDriver.exe.

I figured out that you can specify the name of the exe like so:

IWebDriver driver = new EdgeDriver(
   EdgeDriverService.CreateDefaultService(".", "msedgedriver.exe"));

Hope this works for you.

What is the selenium version you're using? If you're using Selenium 4.00-alpha03 and earlier, you could refer to the following steps to automate Microsoft Edge Chromium:

  • Install the C# Selenium WebDriver 3.141.0 from here.
  • Download the matching version of Microsoft Edge Driver from this page.
  • Example C# code:
using OpenQA.Selenium.Edge;    
using OpenQA.Selenium.Remote;   
using System.Collections.Generic;
using System.Threading;       

var service = EdgeDriverService.CreateDefaultService(@"C:\Selenium\Drivers", @"msedgedriver.exe"); 
service.UseVerboseLogging = true; 
service.UseSpecCompliantProtocol = true; 
service.Start();  
var caps = new DesiredCapabilities(new Dictionary<string, object>() 
{ 
    { "ms:edgeOptions", new Dictionary<string, object>() { 
        { "binary", @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" } 
    }} 
}); 

var driver = new RemoteWebDriver(service.ServiceUrl, caps);  
driver.Navigate().GoToUrl("https://bing.com"); 
Thread.Sleep(2000);  
driver.Close(); 
service.Dispose(); 

Note: Change the paths in the code to your owns.

-----------------------------------------------------------------Update-----------------------------------------------------------

You need to use Selenium 4.00-alpha04 to use the browser-specific options classes when automating Edge Chromium:

  • Download the .NET language binding of Selenium 4.00-alpha04 from here

  • Download the matching version of Microsoft Edge Driver from this page.

  • Example C# code:

using OpenQA.Selenium.Edge; 
using OpenQA.Selenium.Remote;  

EdgeOptions edgeOptions = new EdgeOptions(false);     
edgeOptions.BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"; 
var msedgedriverDir = @"C:\Selenium\Drivers"; 
var msedgedriverExe = @"msedgedriver.exe"; 

var service = EdgeDriverService.CreateDefaultService(msedgedriverDir, msedgedriverExe, false); 
service.EnableVerboseLogging = true; 
var driver = new EdgeDriver(service, edgeOptions); 
driver.Navigate().GoToUrl("https://bing.com"); 
Thread.Sleep(2000); 
driver.Close();

Note: Change the paths in the code to your owns.

driver = new EdgeDriver ("C:\\Selenium\\Drivers\\msedgedriver.exe");

Please remove unnecessary spaces from the path and also include the .exe file in your path

You should not need to download msedgedriver.exe or even know where the PATH to it is.

If you are working with a team or using a build server, it is much better to use this NuGet package:

Selenium.WebDriver.MSEdgeDriver

It will download the exe for you! And you do not have to include it in source control.

These instructions tell how to use Edge/Chromium with Selenium UI Tests, but it does not mention about this very nice NuGet package!

Here is the code from the instructions on how to initialize the driver:

        var options = new EdgeOptions();
        options.UseChromium = true;
        var driver = new EdgeDriver(options);

Replace msedgedriver to MicrosoftWebDriver

Copy driver to the path where Edge browser is located. For example: C:\Program Files (x86)\Microsoft\Edge\Application

Then, use the Edge browser path to initialize the driver:

driver = new EdgeDriver ("C:\Program Files (x86)\Microsoft\Edge\Application");
Related