Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 241
mohammad rostami siahgeli Avatar asked Dec 20 '17 16:12

mohammad rostami siahgeli


People also ask

Where is Chromedriver exe in Selenium?

Below are the steps to follow while configuring the chrome setup for Selenium. #1) Check the version of the chrome. #3) Download the chromedriver.exe file for the respective OS and copy that .exe file into your local. #4) The path of the chromedriver (C:\webdriver\chromedriver.exe) will be used in our program.

How do I get Chromedriver exe?

You can download the chromedriver.exe from this link: https://sites.google.com/a/chromium.org/chromedriver/downloads. You will also find links to previous versions of cromedriver.

How do I add Chromedriver exe to path?

Go to the terminal and type the command: sudo nano /etc/paths. Enter the password. At the bottom of the file, add the path of your ChromeDriver. Type Y to save.

How do I fix Chromedriver executable in path?

To solve the Selenium error "WebDriverException: Message: 'chromedriver' executable needs to be in PATH", install and import the webdriver-manager module by running pip install webdriver-manager . The module simplifies management of binary drivers for different browsers.


1 Answers

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());
like image 130
tehbeardedone Avatar answered Sep 25 '22 04:09

tehbeardedone