Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open the Default Chrome Profile through Selenium, ChromeDriver and GoogleChrome

Tags:

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.)

When I use the following code:

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

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!

like image 328
Nathan Gorham Avatar asked Jul 11 '18 03:07

Nathan Gorham


2 Answers

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");

like image 171
PriorityMark Avatar answered Oct 11 '22 17:10

PriorityMark


The Default Chrome Profile which you use for your regular tasks may contain either/all of the following items:

  • History
  • Bookmarks
  • Cookies
  • Extensions
  • Themes
  • Customized Fonts

All these configurations untill and unless are part of your Test Specification it would be a overkill to load them into the session initiated by Selenium WebDriver. Hence it will be a better approach if you create a dedicated New Chrome Profile for your tests and configure it with all the required configuration.

Here you will find a detailed discussion on How to create and open a Chrome Profile

Once you have created the dedicated New Chrome Profile for your tests you can easily invoke the Chrome Profile as follows:

ChromeOptions options = new ChromeOptions();
options.AddArgument("user-data-dir=C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2");
options.AddArgument("disable-infobars");
options.AddArgument("--start-maximized");
ChromeDriver chromeDriver = new ChromeDriver(options);
chromeDriver.Navigate().GoToUrl("https://www.youtube.com/");

Here you will find a detailed discussion on How to open URL through default Chrome profile using Python Selenium Webdriver

like image 33
undetected Selenium Avatar answered Oct 11 '22 17:10

undetected Selenium