Search code examples
c#selenium-webdriverselenium-chromedriverchrome-optionschrome-profile

Problem when using custom Chrome profile from different location


After I created a custom profile "SeleniumBot" I try to open it using Selenium ChromeDriver and Selenium ChromeOptions. It works just fine for the default path in AppData/Google/Chrome/User Data/SeleniumBot. I get problems when I try to copy the profile folder inside the program/project files and use the --user-data-dir agrument and i put the path to the copy of the profile. The problem is the browser does not start with the stored/saved account to login in gmail.

All solutions I read are about making opening a profile and making one.

My proram needs to run this profile with this particular account on any machine that will not have this custom profile created inside the User Data directory. Any suggestions on how to solve this problem?


Solution

  • I will organize this answer into two scenarios. One if you're using the default chrome profile (shown as: C:\Users\david\AppData\Local\Google\Chrome\User Data\Default) or an added chrome profile (shown as: C:\Users\david\AppData\Local\Google\Chrome\User Data\Profile 1)

    You can check this by typing chrome://version in your search bar.

    Case 1: You are using a default profile.

    1. Navigate to that profile path. Should be something like C:\Users\david\AppData\Local\Google\Chrome\User Data\Default.

    2. Copy and paste that entire folder into whatever place you would like.(ex: D:\Chrome_Profiles). Your directory would look something like this: D:\Chrome_Profiles\Default

    3. Chromedriver automatically adds "Default" to the end of the options.add_argument(r"user-data-dir= part. Thus, you would just use:

      options.add_argument(r"user-data-dir=D:\Chrome_Profiles") driver.get("https://www.facebook.com")

    and you'll see it works just fine.

    2nd case: you're using another chrome profile (noted by Profile 1, Profile 2, etc. in chrome://version)

    1. Navigate to that profile path. Should be something like C:\Users\david\AppData\Local\Google\Chrome\User Data\Profile 1.

    2. Copy and paste that entire folder into whatever place you would like.(ex: D:\Chrome_Profiles). Your directory would look something like this: D:\Chrome_Profiles\Profile 1

    3. Change Profile 1 to Default. Your directory will look something like this: D:\Chrome_Profiles\Default

    4. Chromedriver automatically adds "Default" to the end of the options.add_argument(r"user-data-dir= part. Thus, you would just use:

      options.add_argument(r"user-data-dir=D:\Chrome_Profiles") driver.get("https://www.facebook.com")

    I tested this myself just now and it works. Please let me know if this solved your problem. Thanks!