简体   繁体   中英

Selenium can't find chromedriver.exe

We're upgrading to .NET Core, and we have a crawling engine that uses Selenium for some tasks. We use chromedriver.exe and it works just fine in .NET 4.6.1.

For .NET Core, we created a console application, and added these packages:

  <ItemGroup>
    <PackageReference Include="Selenium.WebDriver" Version="3.8.0" />
    <PackageReference Include="Selenium.Support" Version="3.7.0" />
    <PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="2.34.0" />
  </ItemGroup>

But when I run my code, I get this error:

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 .

I can see that after build, chromedriver.exe is getting copied to bin\\Debug\\netcoreapp2.0 folder. I also copied it manually to bin\\Debug folder. But in both cases it can't be found.

What do I miss here?

I can't explain why it works this way but this is how I got it to work.

IWebDriver driver = new ChromeDriver(".");

I initially copied the driver into the same directory as my Program.cs and passed in the path to the driver like so:

IWebDriver driver = new ChromeDriver("chromedriver.exe");

That resulted in this message:

The file chromedriver.exe\\chromedriver.exe does not exist.

So just for kicks I tried passing in "." for the path and it worked.

This is probably a better solution. The driver needs to be in the same directory as your app code. Not in the /bin directory and this will work.

IWebDriver driver = new ChromeDriver(Directory.GetCurrentDirectory());

I was also facing the same issue and i have fixed it by this way.

First find the version of your Chrome.

Help-> About Google Chrome. There you will find your version number.

then copy URL provided below and place your current Chrome version number into those inverted comma, Then hit Enter. It will directly redirect you to latest download.

https://chromedriver.storage.googleapis.com/index.html?path= " "/ (full URL) Download Zip, Extract it and implement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM