Search code examples
pythonseleniumchrome-profile

How to access a customized profile with selenium?


I am trying to access a gmail account in a customized chrome profile, everything is working, but it seems that I can't load the account:

options.add_argument(f"user-data-dir={expanduser}\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 5")
browser = webdriver.Chrome(ChromeDriverManager().install(), options=options)

To make sure that it does access the right profile, I ran the code and went to chrome://version and it gave me the right path, so is there something wrong with the code ?

I don't know if this can help or not, I just found that when I access the profile manually, the profile path end with the profile name, but when the app opens it, it loads the default inside that profile.

Edit:

Tried to delete that Default Folder, but when the app runs, it recreates it, I think this can be a start point


Solution

  • I found that I need to give the User Data Path, then add another argument to the options called profile-directory and give it the profile name, the final code like this :

    options.add_argument(f"--user-data-dir={expanduser}\\AppData\\Local\\Google\\Chrome\\User Data")
    options.add_argument(f"profile-directory={profile}")