Selenium keeps opening as new User in Chrome

Viewed 66

I've taken a look at several posts around this, but none are helping fix my problem unfortunately

Here is the code I have to open Chrome with a "Selenium" specific profile I just created. I have the latest version of ChromeDriver downloaded for Chrome 83

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument("--user-data-dir=C:\\Users\\Ryan\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 2")

driver = webdriver.Chrome(executable_path=r'C:\Users\Ryan\Workspace\Tools\Selenium\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.com")
1 Answers

I was able to replicate this issue. I can't explain why it's happening, but was able to solve by adding an additional argument. I changed the --user-data-dir to point at the profile home, User Data. I then specified which profile I wanted with --profile_directory.

Here is what I ran on my computer.

ch_options = Options()
ch_options.add_argument("--user-data-dir=C:/Users/jeffg/AppData/Local/Google/Chrome/User Data")
ch_options.add_argument("--profile-directory=Profile 1")   #This is the additional argument
driver = webdriver.Chrome(executable_path=chrome_path, chrome_options=ch_options)

So in your example, it would like something like this:

options = Options()
options.add_argument("--user-data-dir=C:\\Users\\Ryan\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument("--profile-directory=Profile 2")
driver = webdriver.Chrome(executable_path=r'C:\Users\Ryan\Workspace\Tools\Selenium\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.com")

Hope this helps.

Related