26

I'm having some troubles getting Selenium loading a chrome profile.

String pathToChrome = "driver/chromedriver.exe"; System.setProperty("webdriver.chrome.driver", pathToChrome); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); String chromeProfile = "C:\\Users\\Tiuz\\AppData\\Local\\Google\\Chrome\\User Data\\Default"; ArrayList<String> switches = new ArrayList<String>(); switches.add("--user-data-dir=" + chromeProfile); capabilities.setCapability("chrome.switches", switches); WebDriver driver = new ChromeDriver(capabilities); driver.get("http://www.google.com"); 

It starts great and works perfect, but I want to get the default profile loaded because I want to test it with some Extensions enabled and some preferences tested.

Does anybody has an idea why this code isn't working?

I've tested it with Selenium 2.29.1 and 2.28.0 with chromedriver 26.0.1383.0 on windows 7 x64.

1
  • Hi, could you direct me to a tutorial, on how to do this - how to add chrome profiles your your driver? many thanks!
    – snikt
    CommentedJul 30, 2018 at 15:57

8 Answers 8

51

This is an old question, but I was still having a problem getting it to work so I did some more research to understand what was happening. The answer from @PrashanthSams is correct, but I was incorrectly adding \Default to the end of the profile path

I found that Chrome appends \Default to the profile path specified in the user-data-dir. So if your profile path is specified as:

user-data-dir=C:\Users\user_name\AppData\Local\Google\Chrome\User Data\Default\

it will append \Default and you will end up at:

C:\Users\user_name\AppData\Local\Google\Chrome\User Data\Default\Default

which is not the same as the profile that you would get if you opened chrome under that user profile normally.

You can also verify your settings if you open a command prompt, navigate to the chrome executable directory, and run chrome with the options specified similar to this:

chrome.exe --user-data-dir="C:\Users\user_name\AppData\Local\Google\Chrome\User Data"

Finally, you can go to a new tab in Chrome and browse to chrome://version/ you will see the actual profile that is being used. It will be listed like:

Profile Path C:\Users\user_name\AppData\Local\Google\Chrome\User Data\Default

2
  • 9
    To select a different profile, say Profile 1, use options.addArguments("profile-directory=Profile 1");CommentedJun 20, 2018 at 15:59
  • Hi, could you direct me to a tutorial, on how to do this - how to add chrome profiles your your driver? many thanks!
    – snikt
    CommentedJul 30, 2018 at 15:58
21

These combinations did trick for me :)

System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe"); ChromeOptions options = new ChromeOptions(); options.addArguments("user-data-dir=C:/Users/user_name/AppData/Local/Google/Chrome/User Data"); options.addArguments("--start-maximized"); driver = new ChromeDriver(options); 
2
  • 5
    Doesn't work for me, it continues to start with a new clean session
    – singe3
    CommentedJul 24, 2014 at 7:29
  • 2
    This solution didn't work for me either. ` options = webdriver.EdgeOptions() options.add_argument("user-data-dir=C:\\Users\\user_name\\AppData\\Local\\Microsoft\\Edge\\User Data") driver = webdriver.Edge(options=options) driver.maximize_window()`CommentedMar 16, 2020 at 9:53
9

You should try this

op.addArgument("--user-data-dir=C:/Users/username/AppData/Local/Google/Chrome/User Data/"); op.addArgument("--profile-directory=Profile 2"); 
0
    7

    Path where Chrome stores the profiles on Linux.

    String chromeProfilePath = "/home/(user)/.config/google-chrome/Profile3/"; 

    Creating ChromeOptions object, desabling the extensions and adding the profile I want to use by ".addArguments".

    ChromeOptions chromeProfile = new ChromeOptions(); chromeProfile.addArguments("chrome.switches", "--disable-extensions"); chromeProfile.addArguments("user-data-dir=" + chromeProfilePath); 

    As said above by JasonG, after this point Google-Chrome will append \Default to the String you've provided.

    There is a "/Default" folder inside "/Profile3" directory, so what I did was...

    I copied the content of "/Profile3" to the "/Default" folder.

    Set the Browser System Properties and Path as you usually do, call the constructor that receives a ChromeOption and it will work fine.

    WebDriver driver = new ChromeDriver(chromeProfile); 
    2
    • This one is working for me! Thanks, Thiago and JasonG! I tried renaming my existing profile "Profile 6" to "selenium" and copied the contents of "Profile 6" under "selenium\Default" on Windows 10 and it worked.
      – ImtiazeA
      CommentedJul 6, 2018 at 17:32
    • 2
      On Mac I've used String chromeProfilePath = "/Users/<User Name>/Library/Application Support/Google/Chrome";
      – GalAbra
      CommentedOct 25, 2019 at 10:21
    3

    I copied default profile to any other folder and then I do connect to this copy

    ChromeOptions options = new ChromeOptions(); options.AddArgument("--user-data-dir=C:\\AnyFolder"); driver = new ChromeDriver(options); 

    So it uses default profile

      1

      I tried in windows and following code works for me:

      String userProfile= "C:\\Users\\user_name\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\"; ChromeOptions options = new ChromeOptions(); options.addArguments("user-data-dir="+userProfile); options.addArguments("--start-maximized"); WebDriver driver = new ChromeDriver(options); driver.get("http://www.google.com"); 

      How to know whether it is working ?
      One way to know is to run the program twice without killing previous instance of the chrome. If the profile is valid, you'll see the second instance "as a new tab" in the first browser window. If it is not working, you get the second instance "as a new browser window".

        1

        None of these above solutions works for me. And after several hours tirelessly research and trying, I already found out this solution

         System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver"); ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments("--start-maximized"); //chrome://version/ chromeOptions.addArguments("--user-data-dir=/home/{username}/.config/google-chrome"); //load default profile chromeOptions.addArguments("--profile-directory=Default"); 
          0

          According to the ChromeDriver wiki, this is a known issue and is currently not possible.

          https://code.google.com/p/selenium/wiki/ChromeDriver

            Start asking to get answers

            Find the answer to your question by asking.

            Ask question

            Explore related questions

            See similar questions with these tags.