Reputation: 1330
I've been using the NuGet packages for Selenium Webdriver in Visual Studio 2015 with great success. Instead of downloading the chromedriver.exe file and adding it manually, I've done everything via NuGet.
Now, in VS 2017, this doesn't work anymore.
I've added all the necessary NuGet packages: Selenium.WebDriver (3.11.1) and Selenium.Chrome.WebDriver (2.37.0).
However, when I try to instantiate the driver and open Chrome, I get the following exception:
OpenQA.Selenium.DriverServiceNotFoundException: 'The chromedriver.exe file
does not exist in the current directory or in a directory on the PATH
environment variable. The driver can be downloaded at
http://chromedriver.storage.googleapis.com/index.html.'
The whole point for using NuGet (at least in this case) is to NOT download and add the driver manually. But why is this broken?
For cleanliness sake, here is the test code I'm using to instantiate chromedriver:
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
class Program {
public static IWebDriver Instance { get; set; }
static void Main (string[] args) {
var driverService = ChromeDriverService.CreateDefaultService();
driverService.HideCommandPromptWindow = true;
Instance = new ChromeDriver(driverService);
Instance.Navigate().GoToUrl("http://www.nrk.no");
}
}
NB: This is an exact piece of the code I've been using in Visual Studio 2015, so the code SHOULD work normally.
And I know that some people believes that it's better to add chromedriver.exe manually, but I tried that - by Add - Existing Item (and Copy if newer). That doesn't work either; I get the same exception.
Upvotes: 5
Views: 3017
Reputation: 954
I noticed from your comments that you were building for .Net Core. I was having a similar problem where ChromeDriver.exe would end up in the bin dir after build, but it wouldn't be available in the publish folder using dotnet publish, so when I deploy using publish, ChromeDriver.exe wouldn't get copied from the build output directory. If you are experiencing the same problem, or if you don't like the work-around you already did and want to fix it, then you can do what I did:
Edit the project file of the web driver project you are building to set a property named PublishChromeDriver = true. It will look something like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
<IsPackable>false</IsPackable>
<OutputType>Library</OutputType>
<ApplicationIcon />
<StartupObject />
<NeutralLanguage>en</NeutralLanguage>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<!-- Add the following line -->
<PublishChromeDriver>true</PublishChromeDriver>
</PropertyGroup>
...
I suppose you could set the property at the build/publish command line as /p:PublishChromeDriver=true (should work to insert property via build/publish arguments in Azure DevOps, for instance).
The comments on this NuGet issue related to files in NuGet packages not getting published out led me to looking at the ChromeDriver targets file and finding it there.
Upvotes: 2
Reputation: 19
I met the same problem and fixed it. first, when you create a new project, you need to select C#->.net (or .net standard) as the project type. Second, after the new project is created, you could use nuget to install selenium webdriver successfully.
Upvotes: 1