ChromeDriver does not exist in Selenium WebDriver C# test script

前端 未结 10 646
南旧
南旧 2021-02-01 02:24

I have come across a few people with the same issue that seemed to have solved the problem with System.addProperty(\"webdriver.chrome.driver\", \".../chromedriver.exe\");<

相关标签:
10条回答
  • 2021-02-01 02:52

    This was a challenging one to isolate - the clue is in the nuget source which contains Selenium.WebDriver.ChromeDriver.targets - the targets requires an explicit property assignment so chromedriver.exe is never copied to vstest.console deployment directory. Here is the fix to add to your CSPROJ file:

    Assign PublishChromeDriver Property in CSPROJ

      <PropertyGroup>
        <AssemblyName>MyUX.Tests</AssemblyName>
         <!-- ... -->
        <PublishChromeDriver>True</PublishChromeDriver>
      </PropertyGroup>
    

    After this property is defined, a copy of chromedriver.exe will be copied to /bin for vstest.console. This fixes the error we were receiving:

    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
    

    Alternative Approach - Force Copy in CSPROJ

      <Target Name="CopyChromeDriverToBin" BeforeTargets="AfterBuild">
        <Copy SourceFiles="$(ChromeDriverSrcPath)" DestinationFiles="$(TargetDir)$(ChromeDriverName)" SkipUnchangedFiles="true">
        </Copy>
      </Target>
    
    0 讨论(0)
  • 2021-02-01 02:52

    Old question, new answer (for what it's worth): just install the Nuget package Selenium.WebDriver.ChromeDriver. Chromedriver.exe will be in the directory bin/debug on the next build.

    3rd party edit 2017-09

    On this github page jsakamoto/nupkg-selenium-webdriver-chromedriver/ that after running Install-Package Selenium.WebDriver -Version 3.5.2 the chromedriver(.exe) lies below this folder

    " {solution folder} /packages/Selenium.WebDriver.ChromeDriver. {ver} /driver/ {platform}"

    0 讨论(0)
  • 2021-02-01 02:55

    I've installed the nuget package in my c# console application and after build there was no 'chromedriver.exe' in bin/Debug folder. So I manually downloaded the chromedriver for my version of chrome and copied it to the directory manually and then it worked.

    0 讨论(0)
  • 2021-02-01 02:57

    Since you're using C#, you should use the constructor overload for ChromeDriver that allows you to specify the path to the directory containing chromedriver.exe. To wit:

    IWebDriver driver = new ChromeDriver(@"C:\my\path\to\chromedriver\directory");
    
    0 讨论(0)
提交回复
热议问题