问题描述
我想加载一个使用 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 配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!