ChromeDriver does not exist in Selenium WebDriver C# test script

前端 未结 10 942
南旧
南旧 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:48

    you may have enum for your all drivers : 
      public enum Drivers
        {
            Chrome,
            Firefox,
            Safari,
            Edge,
            IE
        }
    
    
      public static IWebDriver GetDriver(Drivers driver)
            {
    

    outPutDirectory -> is a location where all supporting dlls and files are copied when you build the solution. example : C:\Users\Mike\source\repos\Automation\Automation\bin\Debug

         var outPutDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
         // below is my location where I copied all drivers like chromedriver.exe 
    

    relativePath -> is a one of folder being copied when you build soltuion exampple : C:\Users\Mike\source\repos\Automation\Automation\bin\Debug\BrowserDriver

            var relativePath = @"..\..\bin\Debug\BrowserDriver"; 
    

    //So 'chromeDriverPath' will give you exact location of your driver no matter which machine or PC you are running Automation

           var chromeDriverPath = Path.GetFullPath(Path.Combine(outPutDirectory,relativePath));
        // return this driver , just debug this code and check the "outPutDirectory" path
           return new ChromeDriver(chromeDriverPath);
       }
    

提交回复
热议问题