-1

I am trying to open a chrome window that remembers my browser history, cookies, etc. I was able to do this by adding the Chrome Options, BUT when I add these options my driver.get() statement no longer works. The script just opens a chrome window but won't go to the specified website. If I remove the options it takes me to the website, but then I don't have the browser history data I want.

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

PATH = '/Users/myname/Projects/chromedriver'

options = webdriver.ChromeOptions()
options.add_argument('user-data-dir=/Users/myname/Library/Application Support/Google/Chrome/')

driver = webdriver.Chrome(executable_path=PATH, chrome_options=options)

driver.get('https://www.basketball-reference.com/')

I also receive this error:

Traceback (most recent call last):
  File "app_store.py", line 9, in <module>
    driver = webdriver.Chrome(executable_path=PATH, options=options)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/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
knarf123
  • 1
  • 1
  • did you run it in console/terminal to see error messages? – furas Jun 12 '21 at 02:56
  • any particular reason you're using Selenium for this site? – chitown88 Jun 12 '21 at 10:19
  • @furas, I edited the post to show the error I receive – knarf123 Jun 13 '21 at 22:16
  • @chitown88 I'm learning the basics of Selenium so this was just a random website I used. When I have a better understanding of Selenium I'll be using it to automate some forms that I have to fill out on other sites. – knarf123 Jun 13 '21 at 22:20
  • [InvalidArgumentException: Message: invalid argument: user data directory is already in use error using --user-data-dir to start Chrome using Selenium](https://stackoverflow.com/questions/59987080/invalidargumentexception-message-invalid-argument-user-data-directory-is-alre) – furas Jun 13 '21 at 23:22
  • https://stackoverflow.com/questions/59987080/invalidargumentexception-message-invalid-argument-user-data-directory-is-alre – chitown88 Jun 14 '21 at 06:38

2 Answers2

1

I think you've got a syntax error here

driver = webdriver.Chrome(executable_path=PATH, chrome_options=options)

The argument is just options, so it should be

driver = webdriver.Chrome(executable_path=PATH, options=options)
C. Peck
  • 3,641
  • 3
  • 19
  • 36
-2

Try making two different drivers, one for Chrome Options and one for the website.