如何通过Selenium,ChromeDriver和GoogleChrome打开默认的Chrome配置文件 [英] How to open the Default Chrome Profile through Selenium, ChromeDriver and GoogleChrome
问题描述
我想加载一个使用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);
我的其余代码可以完美执行(请注意,在第一个参数末尾添加了"Default").关于如何获得第一段代码(末尾没有"Default"的代码)以执行程序其余部分的任何提示或建议都很好.谢谢!
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配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!