简体   繁体   English

为什么 ChromeDriver 可以在 Debug 模式下工作,但不能在发布时工作?

[英]Why is ChromeDriver working in Debug mode but not on release?

So I have this c# console app that I'm creating.所以我有我正在创建的这个c# 控制台应用程序

It uses Selenium ChromeDriver to create WordPress menus.它使用 Selenium ChromeDriver 创建 WordPress 菜单。 It's working perfectly on debug mode.它在调试模式下完美运行。

Now I release it and when I install the app, run it, it's giving me this error:现在我发布它,当我安装应用程序时,运行它,它给了我这个错误:

The chromedriver.exe file does not exist in the current t directory or in a directory on the PATH environment variable. chromedriver.exe 文件不存在于当前 t 目录或 PATH 环境变量上的目录中。

This is where I believe I'm getting this error:这是我相信我收到此错误的地方:

ChromeOptions options = new ChromeOptions();
options.AddArgument("start-maximized");
driver = new ChromeDriver(options);

I've searched all over the internet but nothing seems to work, I think it's something that has to do with Publishing in Visual Studio.我在互联网上进行了搜索,但似乎没有任何效果,我认为这与在 Visual Studio 中发布有关。

将 chromedriver.exe 从 Debug 文件夹复制到 Release 文件夹。

Presuming you have installed the NuGet package Selenium.WebDriver.ChromeDriver .假设您已经安装了 NuGet 包Selenium.WebDriver.ChromeDriver You will find the latest chrome driver in \\Selenium.WebDriver.ChromeDriver\\driver\\win32\\chromedriver.exe select the correct version based on system.您将在\\Selenium.WebDriver.ChromeDriver\\driver\\win32\\chromedriver.exe找到最新的 chrome 驱动程序,根据系统选择正确的版本。

Add the file to your project, then in the file properties select under "Copy to Output Directory" either "Copy Always" or "Copy if Newer".将文件添加到您的项目,然后在“复制到输出目录”下的文件属性中选择“始终复制”或“如果较新则复制”。

This question should help这个问题应该有帮助

Selenium WebDriver.ChromeDriver Nuget package installed, but not working for MSTest 已安装 Selenium WebDriver.ChromeDriver Nuget 包,但不适用于 MSTest

From the project owner github page:从项目所有者github页面:

"chromedriver(.exe) isn't included in published files on default configuration. This behavior is by design." “chromedriver(.exe) 不包含在默认配置的已发布文件中。此行为是设计使然。”

If you want to include "chromedriver(.exe)" into published files, please define "_PUBLISH_CHROMEDRIVER" compilation symbol (Under Project > Properties > Build)如果要将“chromedriver(.exe)”包含到已发布的文件中,请定义“_PUBLISH_CHROMEDRIVER”编译符号(在项目> 属性> 构建下)

在此处输入图片说明

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

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