硒找不到chromedriver.exe [英] Selenium can't find chromedriver.exe

查看:461
本文介绍了硒找不到chromedriver.exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在升级到.NET Core,并且我们有一个使用Selenium进行某些任务的爬网引擎.我们使用chromedriver.exe,它在.NET 4.6.1中可以正常工作.

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.

对于.NET Core,我们创建了一个控制台应用程序,并添加了以下软件包:

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:

chromedriver.exe文件在当前目录中不存在,或者 在PATH环境变量上的目录中.司机可以 在 http://chromedriver.storage.googleapis.com/index.html 下载.

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.

我可以看到在构建之后,chromedriver.exe被复制到了bin\Debug\netcoreapp2.0文件夹中.我还手动将其复制到了bin\Debug文件夹.但是在两种情况下都找不到.

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.

我在这里想念什么?

推荐答案

我无法解释为什么这种方式起作用,但这就是我如何使其起作用的方式.

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

IWebDriver driver = new ChromeDriver(".");

我最初将驱动程序复制到与我的Program.cs相同的目录中,并像这样传递到驱动程序的路径中:

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

导致此消息:

文件chromedriver.exe \ chromedriver.exe不存在.

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

所以只是为了踢球,我尝试将"."传递给路径,并且它起作用了.

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

这可能是一个更好的解决方案.驱动程序必须与您的应用程序代码位于同一目录中.不在/bin目录中,它将起作用.

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

这篇关于硒找不到chromedriver.exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆