Reputation: 175
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?
Upvotes: 1
Views: 754
Reputation: 51
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)
Upvotes: 0
Reputation: 33371
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
Upvotes: 0
Reputation: 832
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.
Upvotes: 0