7

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?

ouflak
  • 2,458
  • 10
  • 44
  • 49
Manu
  • 81
  • 1
  • 3
  • Does [this question](https://stackoverflow.com/questions/56076421/selenium-and-edge-dev-chromium-based) help you? – Mat J Mar 03 '20 at 06:37
  • You can use [https://github.com/microsoft/edge-selenium-tools](https://github.com/microsoft/edge-selenium-tools) to have compatibility with Selenium 3, it is available through Nuget, note that the driver is not inside this nuget. – Jarvars Jun 17 '20 at 16:53

5 Answers5

6

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.

Ambrose Leung
  • 3,704
  • 2
  • 25
  • 36
2

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.

Yu Zhou
  • 11,532
  • 1
  • 8
  • 22
  • Selenium version 3.141.0 – Manu Mar 03 '20 at 17:10
  • Have you tried the code I provided? It is suitable for selenium 3.141.0 and can work well to automate Edge webdriver. I think it's not the wrong driver version, but some mistakes in your code which lead to the error. – Yu Zhou Mar 04 '20 at 01:33
  • When I write the code you provide me it works correctly, but Visual studio tells me that the use of desiriedCapabilities is deprecated and that I have to use browser-specific options classes – Manu Mar 08 '20 at 17:07
  • If you want to use Edge browser-specific options classes, you need to use selenium 4.00-alpha04. Please check my updates. If you use selenium 3.141.0 and use Edge options, it will point to Edge Legacy and use Edge Legacy webdriver MicrosoftWebDriver.exe. – Yu Zhou Mar 09 '20 at 02:31
2
driver = new EdgeDriver ("C:\\Selenium\\Drivers\\msedgedriver.exe");

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

  • I don't have those space. It was a mistake to write it – Manu Mar 03 '20 at 17:05
  • 3
    if I do this the message just changes to ": The file c:\WebDriver\msedgedriver.exe\MicrosoftWebDriver.exe does not exist" – Joel Aug 20 '20 at 17:30
  • Please see my answer. You do not need to download msedgedriver.exe nor include the path to the exe in the constructor code. – Jess May 11 '21 at 13:25
1

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);
Jess
  • 23,901
  • 21
  • 124
  • 145
-1

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");