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

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!

2 answers

  • answered 2018-07-11 07:34 Buaban

    I have the same issue. I don't know how to fix it, I guess the root cause is white space in profile path.

    I know a workaround for this. Just copy the C:\\Users\\Andrea\\AppData\\Local\\Google\\Chrome\\User Data to c:\myUserData (no space in the path).

    Then add the argument.

    options.AddArgument("user-data-dir=C:\\myUserData");
    

  • answered 2018-07-11 07:36 New contributor

    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