How to open the Default Chrome Profile through Selenium, ChromeDriver and GoogleChrome(如何通过 Selenium、ChromeDriver 和 GoogleChrome 打开默认 Chrome 配置文件)
问题描述
我想加载一个使用 Chrome 的新 Selenium ChromeDriver,就像我从我的扩展坞打开 Chrome 一样(基本上它会包含我所有的扩展程序、历史记录等)
I want to load a new Selenium ChromeDriver that is using Chrome as if I open Chrome from my dock (Essentially it'll have all my extensions, history, etc.)
当我使用以下代码时:
ChromeOptions options = new ChromeOptions();
options.AddArgument("user-data-dir=C:\Users\User\AppData\Local\Google\Chrome\User Data\");
options.AddArgument("disable-infobars");
options.AddArgument("--start-maximized");
ChromeDriver chromeDriver = new ChromeDriver(options);
它会加载 Chrome 浏览器,让我登录到我的 Gmail 和我的所有扩展程序,就像我想要的那样,但我的其余代码:
It loads the Chrome browser with me signed into my Gmail and with all my extensions, just like I want, but the rest of my code:
chromeDriver.Navigate().GoToUrl("https://www.youtube.com/");
不执行.但是当我使用以下
doesn't execute. But when I use the following
ChromeOptions options = new ChromeOptions();
options.AddArgument("user-data-dir=C:\Users\Andrea\AppData\Local\Google\Chrome\User Data\Default");
options.AddArgument("disable-infobars");
options.AddArgument("--start-maximized");
ChromeDriver chromeDriver = new ChromeDriver(options);
我的其余代码完美执行(请注意添加到第一个参数末尾的默认").关于如何获得第一个代码块(最后没有默认"的那个)来执行我的程序其余部分的任何提示或建议都会很棒.谢谢!
The rest of my code executes perfectly (Notice the 'Default' added to the end of the first Argument). Any tips or suggestions on how I can get the first block of code (The one without 'Default' on the end) to execute the rest of my program would be great. Thanks!
推荐答案
我知道这是一个老问题,但对我有用的是删除C:"并将所有反斜杠替换为正斜杠.因此,从原始问题来看,这应该可以加载默认配置文件:
I know this is an old question, but what worked for me is to do remove the "C:" and replace all of the backslashes with forward slashes. So, with that from the original question, this should work to load the default profile:
options.AddArgument("user-data-dir=/Users/User/AppData/Local/Google/Chrome/User Data");
这篇关于如何通过 Selenium、ChromeDriver 和 GoogleChrome 打开默认 Chrome 配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何通过 Selenium、ChromeDriver 和 GoogleChrome 打开默认 Chrome 配置文件


- MoreLinq maxBy vs LINQ max + where 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- C# 中多线程网络服务器的模式 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01