1

Here's my code:

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

options = Options()
options.add_argument(r'--user-data-dir=C:\Users\Winsome\AppData\Local\Google\Chrome\User Data')
options.add_argument('--profile-directory=Profile 4')
options.add_experimental_option('excludeSwitches', ['enable-logging'])
options.add_argument('log-level=3')

driver = webdriver.Chrome(executable_path='chromedriver', options=options)
driver.get("https://github.com")

When I run the code, I get an error:

Traceback (most recent call last): File "app.py", line 10, in driver = webdriver.Chrome(executable_path='chromedriver', options=options) File "C:\Users\Winsome\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in init desired_capabilities=desired_capabilities) File "C:\Users\Winsome\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in init self.start_session(capabilities, browser_profile) File "C:\Users\Winsome\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "C:\Users\Winsome\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\Winsome\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir

I am sure that I have no chrome windows open, but I don't know why I'm getting the error :( Can anyone help?

5
  • What OS are you using? Commented Jul 21, 2021 at 11:29
  • Obviously, Windows. Commented Jul 21, 2021 at 11:30
  • Well can you check your argument which you are passing in the .add_argument() I can see it displays InvalidArgumentException: Message: invalid argument Commented Jul 21, 2021 at 11:42
  • @YaDavMaNish Can you give me the code for that? Commented Jul 21, 2021 at 11:46
  • @AbhirajshriWinsome check the ref link in the answer Commented Jul 21, 2021 at 11:48

3 Answers 3

0

Closing all Chrome tabs does not mean that Chrome is not running in the background.

For Windows, please open Task Manager (Ctrl + Alt + Delete) and look in the Processes tab for any Chrome related processes.

Sign up to request clarification or add additional context in comments.

1 Comment

I even restarted my PC, but same error again :(
0

Remove this line

options.add_argument(r'--user-data-dir=C:\Users\Winsome\AppData\Local\Google\Chrome\User Data')

from your code.
Read here for more deep and clear explanations

6 Comments

But it is loading the page in some anonymous profile... but I wanted in profile 4 only
I see. have you tried to set user-data-dir as ..\User Data\Default to access the Default Chrome Profile as described there?
Yes, I did. But still it's opening in some anyonymous profile
Well, I currently have no much time, sorry. Upvoted and leaved for now :)
:'( ok, I'll be waiting until you reply
|
0

Reference PC Build info: Windows 11 (22622.290), Google Chrome (103.0.5060.114), selenium (4.3.0), ChromeDriver (103.0.5060.53)

I confirmed that this worked for me:

from selenium import webdriver

# add chrome options
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("user-data-dir=C:\\Users\\dtada\\AppData\\Local\\Google\\Chrome\\User Data")
chrome_options.add_argument('--profile-directory=Profile 1')
# point to path of chromedriver
s = Service('C:/bin/chromedriver.exe')
# initialize the Chrome driver
driver = webdriver.Chrome(service=s, service_args=["--verbose", "--log-path=C:\\bin\\qc1.log"], options=chrome_options)

# go to webpage
driver.get(url)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.