Home > other >  selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory

Time:12-17

I'm trying to open website in my real Chrome not a driver But i got list of Errors and it does't open the url** Here is my code

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

s = Service("C:\\Users\\Administrator\\Desktop\\chromedriver.exe")

options = webdriver.ChromeOptions() 
options.add_argument("--user-data-dir=C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument('--profile-directory=Default')
driver = webdriver.Chrome(service=s, chrome_options=options)

driver.get("https://www.instagram.com")

The Errors Like :

  C:\Users\Administrator\Desktop\Py Sele\Sele.py:11: DeprecationWarning: use options instead of chrome_options
  driver = webdriver.Chrome(service=s, chrome_options=options)
Opening in existing browser session.
Traceback (most recent call last):
  File "C:\Users\Administrator\Desktop\Py Sele\Sele.py", line 11, in <module>
    driver = webdriver.Chrome(service=s, chrome_options=options)
  File "C:\Program Files\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 70, in __init__
    super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "C:\Program Files\Python39\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 93, in __init__
    RemoteWebDriver.__init__(
  File "C:\Program Files\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 268, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Program Files\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 359, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Program Files\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 424, in execute
    self.error_handler.check_response(response)
  File "C:\Program Files\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, 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
Stacktrace:
Backtrace:

CodePudding user response:

This error message...

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

...implies that the --user-data-dir is already in use.

Your main issue is you have already an open Google Chrome browser session opened for your manual browsing.

There is no such error in your code block. However it seems you are executing program as an Administrator. But,

A common cause for Chrome to crash during startup is running Chrome as root user (administrator) on Linux. While it is possible to work around this issue by passing --no-sandbox flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Chrome as a regular user instead.


Solution

Before you execute your test as an user e.g. Administrator, ensure that you don't have any open Chrome browser windows using the same user i.e. Administrator.

  • Related