8

I'm getting the following error when I try to open the EdgeDriver.

OpenQA.Selenium.WebDriverException: 'Cannot start the driver service on http://localhost:20548/'

The FirefoxDriver and ChromeDriver work just fine.

enter image description here

This is an issue with the driver?

There is nothing running on port 20548. The below code returns nothing.

C:\WINDOWS\system32>netstat -a -o | find "20548"

Did I need to do anything else besides downlowd the Selenium.WebDriver.MicrosoftWebDriver NuGet into my project?

enter image description here

The only software I need installed on my computer is the latest version of Microsoft Edge correct? enter image description here

Fractal
  • 1,592
  • 5
  • 23
  • 40

3 Answers3

5

OpenQA.Selenium.WebDriverException: 'Cannot start the driver service on http://localhost:20548/'

As for this issue, It could be the case that a process of the WebDriver is still running in the background. Please try to fire up Task Manager to see and end it if does.

Otherwise, you could try to use the following code to assign the webdeiver server:

        var driverpath = @"C:\Program Files (x86)\Microsoft Web Driver"; //find the web driver path
        var driver = new EdgeDriver(driverpath);
        // Navigate to Bing
        driver.Url = "https://www.bing.com/";

        // Find the search box and query for webdriver
        var element = driver.FindElementById("sb_form_q");

        element.SendKeys("webdriver");
        element.SendKeys(Keys.Enter);

        Console.ReadLine();
        driver.Quit();

This version of MicrosoftWebDriver.exe is not compatible with the installed version of Windows 10.

Please check this article to download the related Microsoft WebDriver version based on your Edge browser version.

Then, you could refer to this article to use WebDriver.

Zhi Lv
  • 15,351
  • 1
  • 10
  • 21
3

I tried running MicrosoftWebDriver.exe that was in the bin directory of my project (project name, Test). This gave me the answer I needed.

enter image description here

I downloaded the correct driver from the following website:

https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/#downloads

enter image description here

========================================================

Further Update & Solution: How to know which driver to get ...

I finally found the correct driver. There are two ways to get the driver.

  1. By downloading it from the Microsoft developer website
  2. Find it in the visual studio NuGet manager and let the manger configure it into your project (preferred method)

Method 1: how to know which driver to download

  1. Go to the Microsoft developer website
  2. Find the Release which has a Release number equal to the version number on your Edge browser enter image description here
  3. Configure your project to locate and use the MicrosoftWebDriver.exe you downloaded

Method 2: how to know which driver to download

  1. Open your test project in VS and open the NuGet package manager
  2. Browse for the Selenium.WebDriver.MicrosoftWebDriver
    • Find the version of the webdriver where the last half of the version number matches the last half of your edge browser's Microsoft EdgeHTML version number (not obvious at all). enter image description here
  3. Click in install button. everything will automatically be configured in your project so you can automatically start using the driver

  4. Add the few lines of Selenium code to your test project which will open the edge browser (shown in the original question).

Fractal
  • 1,592
  • 5
  • 23
  • 40
  • 1
    Given that the NuGet package you’re referencing (`Selenium.WebDriver.MicrosoftWebDriver`) is maintained by neither the Selenium project, nor Microsoft, I would be careful about trusting that the package is properly maintained. Moreover, since the situation is similar for all other browser-specific driver executables, I’d hesitate to call managing driver executables via NuGet “preferred” as a general rule. – JimEvans Jun 06 '19 at 18:44
  • @JimEvans do you know if there is a NuGet for the Edge webdriver which was created by Microsoft or Selenium? If so, do you know the name of it? I looked around for one but did not find anything. – Fractal Jun 11 '19 at 19:00
  • 1
    That was rather the point of my comment, that there _**is**_ no official NuGet packaging. There are not likely _**to be**_ official NuGet packaging. In my opinion, using NuGet to manage random binaries (instead of referenced assemblies, its actual purpose) is an abuse of the intent of the NuGet system. – JimEvans Jun 12 '19 at 05:44
  • @JimEvans. Managing (downloading and configuring your project to reference those downloads) drivers through the NuGet manager is the taught and mainstream way to manage drivers when working with Selenium. And all discussions on working with C# Selenium will direct you to download the drivers via the VS command line package manager or the VS UI Nuget package manager. You have left me wondering since you say this is not correct yet this is the main (pretty much only) way shown/suggested for managing drivers with C# Selenium in VS. – Fractal Jun 12 '19 at 14:04
  • 1
    The “taught and mainstream way?” Taught by whom? I’m not an expert at NuGet, and don’t claim to be. I _**do**_ consider myself, if not an expert, at least knowledgeable about Selenium/WebDriver on the .NET development stack. I do not prefer using NuGet for managing driver executables for the reasons I previously outlined. If that mechanism works for someone, they should use it, but I can under no circumstances consider it “correct.” – JimEvans Jun 13 '19 at 01:00
  • apologies for all the questions. I'm somewhat new to the testing world. So instead of managing the drivers through the NuGet manager (via Selenium.Driver.ChromeDriver), you instead download the driver, probably put it somewhere like the Program Files directory and then add it to your Windows Path environment variables? Similar to what is suggested in the "ADDING THE DRIVER EXECUTABLE" from this article (https://saucelabs.com/resources/articles/getting-started-with-webdriver-in-c-using-visual-studio)? Doesn't that make it difficult to transport the solution to different machines? – Fractal Jun 13 '19 at 12:39
  • And difficult for keeping track of project references via source control? – Fractal Jun 13 '19 at 12:41
  • 1
    You have many possibilities of managing driver executables. You can put them in a directory on the path, as you suggested. You can put them in a well-known location, and use the constructor overload that takes a path to the executable. You can include them in your solution and have them copied to the output directory at compile time. Any of these and more would be valid approaches. – JimEvans Jun 13 '19 at 23:14
  • Okay, I was just wondering what your preference was. That makes sense. Thanks again for the discussion. – Fractal Jun 14 '19 at 00:26
0

on selecting multiple run setting files also, we are getting this error.

To solve this problem, we have to deselect all the selected run setting file from Test tab on VS and select any one run setting file then run your test case