简体   繁体   中英

The chromedriver.exe file does not exist when using ClickOnce

I used ChromeDriver of Selenium to do some automatic tasks. The window form run well in my machine, but when it deployed and user installed window form by ClickOnce. It show error:

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 .

Here is the code for create new instance of ChromeDriver:

private static IWebDriver driver = new ChromeDriver();

I searched some solution to add chromedriver.exe in project with specific folder:

private static IWebDriver driver = new ChromeDriver(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ChromeDriver"));

But it didnt' work too. I think ClickOnce prevent exe file when install to client machine. Any solution for this case? Thanks.

I am not sure how you are getting the chrome driver but here is a suggestion.

  1. Use the chrome driver nuget package

  2. On your Solution name, right click Properties

  3. On Build Tab Add the below:

    Conditional compilation symbols: _PUBLISH_CHROMEDRIVER

    Output Path: bin\Debug\

  4. Rebuild solution and you should see chromedriver.exe in bin\debug

Then you can use something like this:

                case "chrome":
                    ChromeDriverService service = ChromeDriverService.CreateDefaultService(Path.Combine(GetBasePath, @"bin\Debug\"));
                    ChromeOptions options = new ChromeOptions();
                    options.AddArgument("--ignore-ssl-errors=yes");
                    options.AddArgument("--ignore-certificate-errors");
                    driver = new ChromeDriver(service, options);
                    driver.Manage().Window.Size = new System.Drawing.Size(1920, 1280);
                    break;

Using this will help if you are running locally on C: but may have Jenkins setup on E:

    public static string GetBasePath
    {
        get
        {
            var basePath =
                System.IO.Path.GetDirectoryName((System.Reflection.Assembly.GetExecutingAssembly().Location));
            basePath = basePath.Substring(0, basePath.Length - 10);
            return basePath;
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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