Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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# 以selenium用户身份打开Chrome_C#_Selenium_Google Chrome - Fatal编程技术网

C# 以selenium用户身份打开Chrome

C# 以selenium用户身份打开Chrome,c#,selenium,google-chrome,C#,Selenium,Google Chrome,当前在使用默认浏览器打开Selenium浏览器时遇到问题。我已通过AddArgument函数指定了用户数据配置文件的正确路径。(我访问时指定的chrome://version/ 已登录)。然而,无论我如何无法访问我登录的默认chrome实例。这是我使用的代码 static void Main(string[] args) { ChromeOptions options = new ChromeOptions(); options.AddA

当前在使用默认浏览器打开Selenium浏览器时遇到问题。我已通过AddArgument函数指定了用户数据配置文件的正确路径。(我访问时指定的chrome://version/ 已登录)。然而,无论我如何无法访问我登录的默认chrome实例。这是我使用的代码

static void Main(string[] args)
    {
        ChromeOptions options = new ChromeOptions();
        
        options.AddArgument(@"user-data-dir=C:\Users\user\AppData\Local\Google\Chrome\User Data\Profile 2");
       
        ChromeDriver chromeDriver = new ChromeDriver(options);
        chromeDriver.Navigate().GoToUrl("https://www.google.com/");

    }

Chrome有一个用于存储配置文件的用户数据目录。在此目录中,可以维护多个配置文件。可以使用两个参数

  • 用户数据目录
  • 配置文件目录

  • 如果仅指定了
    用户数据目录
    ,则将使用该目录中的
    默认
    目录。如果指定了
    配置文件目录
    ,则使用
    用户数据目录
    中的目录

    感谢您的回复。我尝试切换到配置文件目录。然而,这是不成功的。它现在打开了一个窗口,我可以选择以来宾身份浏览,并提供了以用户身份登录的选项。有什么想法吗?问题是什么?这是更改后的代码:options.AddArgument(@“profile directory=C:\Users\user\AppData\Local\Google\Chrome\user Data\profile 2”);