1
votes

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?

2
What OS are you using? - Joep
Obviously, Windows. - Abhirajshri Winsome
Well can you check your argument which you are passing in the .add_argument() I can see it displays InvalidArgumentException: Message: invalid argument - YaDav MaNish
@YaDavMaNish Can you give me the code for that? - Abhirajshri Winsome
@AbhirajshriWinsome check the ref link in the answer - YaDav MaNish

2 Answers

0
votes

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.

0
votes

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