简体   繁体   English

Selenium找不到chromedriver.exe

[英]Selenium can't find chromedriver.exe

We're upgrading to .NET Core, and we have a crawling engine that uses Selenium for some tasks. 我们正在升级到.NET Core,我们有一个使用Selenium进行某些任务的爬行引擎。 We use chromedriver.exe and it works just fine in .NET 4.6.1. 我们使用chromedriver.exe ,它在.NET 4.6.1中运行良好。

For .NET Core, we created a console application, and added these packages: 对于.NET Core,我们创建了一个控制台应用程序,并添加了这些包:

  <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. chromedriver.exe文件不存在于当前目录或PATH环境变量的目录中。 The driver can be downloaded at http://chromedriver.storage.googleapis.com/index.html . 该驱动程序可以从http://chromedriver.storage.googleapis.com/index.html下载。

I can see that after build, chromedriver.exe is getting copied to bin\\Debug\\netcoreapp2.0 folder. 我可以看到,在构建之后, chromedriver.exe被复制到bin\\Debug\\netcoreapp2.0文件夹中。 I also copied it manually to bin\\Debug folder. 我也手动将它复制到bin\\Debug文件夹。 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: 我最初将驱动程序复制到与Program.cs相同的目录中,并将路径传递给驱动程序,如下所示:

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

That resulted in this message: 这导致了这个消息:

The file chromedriver.exe\\chromedriver.exe does not exist. 文件chromedriver.exe \\ chromedriver.exe不存在。

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. 不在/bin目录中,这将起作用。

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. 首先找到您的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. 然后复制下面提供的URL并将当前的Chrome版本号放入那些倒置的逗号中,然后按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. https://chromedriver.storage.googleapis.com/index.html?path= “”/(完整网址)下载Zip,解压缩并实施。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 chromedriver.exe 未在 selenium c# 中关闭 - chromedriver.exe not closing in selenium c# 在不成功 selenium ChromeDriver 创建期间 chromedriver.exe 没有被处理 - During unsuccessful selenium ChromeDriver creation chromedriver.exe is not being disposed 在哪里放chromedriver.exe以发布Selenium WebDriver C# - Where to put chromedriver.exe for release of Selenium WebDriver C# 如何识别chromedriver.exe? - How to identify chromedriver.exe? Selenium.WebDriver.ChromeDriver - chromedriver.exe没有为netcore2.2目标框架发布 - Selenium.WebDriver.ChromeDriver - chromedriver.exe is not being publishing for netcore2.2 target framework c# OpenQA.Selenium.WebDriverException:对于 chromedriver.exe(nuget pkg 版本 2.46.0) - c# OpenQA.Selenium.WebDriverException : for chromedriver.exe (nuget pkg version 2.46.0) 如果无法实例化修复 Session 未创建,请尝试 Selenium 下载使用 C# 中的最新 chromedriver.exe - Try Selenium Download use of Latest chromedriver.exe in C# if it Fails to Instanciate to fix Session not created Exception 如何在 C# 中隐藏 chromedriver.exe 控制台窗口? - How to hide the chromedriver.exe console window in C#? 运行多个测试用例时,chromedriver.exe挂起 - chromedriver.exe hangs when running multiple test cases 使用 ClickOnce 时 chromedriver.exe 文件不存在 - The chromedriver.exe file does not exist when using ClickOnce
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM