Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Visual Studio 2015和Selenium:添加chromedriver_C#_Visual Studio 2015_Selenium Chromedriver - Fatal编程技术网

C# Visual Studio 2015和Selenium:添加chromedriver

C# Visual Studio 2015和Selenium:添加chromedriver,c#,visual-studio-2015,selenium-chromedriver,C#,Visual Studio 2015,Selenium Chromedriver,VS从未停止让我惊讶。或者,更确切地说,它从未停止让我惊讶的是,我是如何忘记在每次创建新解决方案之间如何做事情,或者在两个解决方案之间事情似乎是如何变化的 我正在尝试使用含硒的ChromeDriver(在C#中)。我已经在项目中安装了Selenium.Webdriver和Selenium.Chrome NuGet软件包,一切看起来都很好。using指令上没有错误,尝试创建新ChromeDriver时也没有错误 以下是Selenium驱动程序代码: using OpenQA.Selenium; u

VS从未停止让我惊讶。或者,更确切地说,它从未停止让我惊讶的是,我是如何忘记在每次创建新解决方案之间如何做事情,或者在两个解决方案之间事情似乎是如何变化的

我正在尝试使用含硒的ChromeDriver(在C#中)。我已经在项目中安装了Selenium.Webdriver和Selenium.Chrome NuGet软件包,一切看起来都很好。using指令上没有错误,尝试创建新ChromeDriver时也没有错误

以下是Selenium驱动程序代码:

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System.Threading;

...

public class GCDriver {
    public static IWebDriver Instance { get; set; }

    public static void Initialize () {
        Instance = new ChromeDriver();
    }

    public static void Wait(TimeSpan timeSpan) {
        Thread.Sleep((int)(timeSpan.TotalSeconds * 1000));
    }

    public static void Close() {
        Instance.Quit();
    }
}
当我像往常一样尝试启动(初始化)ChromeDriver时,会出现以下错误:

Test Name:  One
Test FullName:  MyTests.TestUnitTest1.One
Test Source:    C:\Users\149999frho\Source\Workspaces\QA\Automation\MyTests\TestUnitTest1.cs : line 17
Test Outcome:   Failed
Test Duration:  0:00:00,0118783

Result StackTrace:  
at OpenQA.Selenium.DriverService.FindDriverServiceExecutable(String    executableName, Uri downloadUrl)
   at OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService()
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeOptions options)
   at OpenQA.Selenium.Chrome.ChromeDriver..ctor()
   at Automation.GCDriver.Initialize() in C:\Users\149999frho\Source\Workspaces\QA\Automation\Automation\Selenium\GCDriver.cs:line 16
   at MyTests.TestUnitTest1.Init() in C:\Users\149999frho\Source\Workspaces\QA\Automation\MyTests\TestUnitTest1.cs:line 12
Result Message: Initialization method MyTests.TestUnitTest1.Init threw    exception. OpenQA.Selenium.DriverServiceNotFoundException:    OpenQA.Selenium.DriverServiceNotFoundException: 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位于Solution\Project\Automation\bin\Debug文件夹中。应该如此,因为安装了NuGet软件包

我错过了什么?安装NuGet软件包后,我是否必须添加任何其他引用?添加chromedriver.exe文件作为引用是不可能的,顺便说一句,VS抱怨它不是实际的COM引用或类似的东西

不过,引用似乎是有序的,而且references文件夹看起来与其他解决方案中的情况完全相同:

更新: 我找到了一个解决方法:在创建chromedriver的新实例时,将路径添加到chromedriver.exe文件。实例=新的ChromeDriver()。然而,这是一个愚蠢且无用的解决方案,因为我必须使用绝对路径-VS不接受相对路径。当共享一个项目时,它将完全无法管理


所以问题是,项目不知道它自己的NuGet包管理器安装的文件位于何处。啊!在这个价格范围内,一个软件怎么可能做到这一点

我也经历过这种情况。可悲的是,我从未找到解决方案或答案。在一次又一次的尝试之后,一次又一次地创建新的项目和解决方案——总是相同的——它最终会成功。