繁体   English   中英

Selenium C# - ChromeDriverService.CreateDefaultService() System.ComponentModel.Win32Exception: '目录名无效'

[英]Selenium C# - ChromeDriverService.CreateDefaultService() System.ComponentModel.Win32Exception: 'The directory name is invalid'

尝试使用其他用户运行 chrome 时出现此错误。 我似乎无法弄清楚为什么我收到错误

程序集目录和 chromedriver.exe 似乎是正确的,但由于某种原因,chrome 浏览器无法启动

Nuget 包 Selenium.Webdriver.ChromeDriver = 81.0.4044.13800

Chrome = 版本 81.0.4044.138(官方版本)(64 位)

 private static RemoteWebDriver OpenChromeBrowser(string userName)
        {
            Console.WriteLine("Entering Chromesetup");
            var driverPath = CommonHelper.AssemblyDirectory;
       

            Console.WriteLine($"Assembly Directory : {driverPath}");
               var service = ChromeDriverService.CreateDefaultService(driverPath); //Error seems to happen here

在此处输入图片说明

在此处输入图片说明

这是我对 chrome 的大部分调用的样子。 您不应在通话中调用 chromedriver.exe。 只需使用该目录作为文件的位置。

                    ChromeDriverService service = ChromeDriverService.CreateDefaultService(Path.Combine(GetBasePath, @"bin\Debug\"));
                    ChromeOptions options = new ChromeOptions();
                    options.AddArguments("--incognito");
                    driver = new ChromeDriver(service, options);
                    driver.Manage().Cookies.DeleteAllCookies();


            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;
        }
    }
    

暂无
暂无

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

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