0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python-Selenium-Chrome でユーザープロフィールを指定してChromeを起動させたい

Last updated at Posted at 2019-03-01

Python-Selenium-Chromeで、下記のページを参考に、既にChrome上で設定済みのユーザープロフィールを指定してChromeを起動させたいです。

【参考ページ】
Python + Selenium + Chrome で自動ログインいくつか
の『既存のユーザプロファイルを使う』の部分

しかし、以下のようなコードでChromeを起動させると、下記のエラーが出てしまいます。

何が原因か、ご教示いただけたら幸いです。
よろしくお願い致します。

from selenium import webdriver

chrome_user_data_dir_path = 'C:\\Users\\[UserName]\\AppData\\Local\\Google\\Chrome\\User Data'
chrome_user_profile_directory = 'Profile 1'
options = webdriver.ChromeOptions()
options.add_argument('--user-data-dir=' + chrome_user_data_dir_path)
options.add_argument('--profile-directory=' + chrome_user_profile_directory)
browser = webdriver.Chrome(options=options)
[14396:9608:0301/174908.325:ERROR:cache_util_win.cc(19)] Unable to move the cache: 0
[14396:9608:0301/174908.328:ERROR:cache_util.cc(140)] Unable to move cache folder C:\Users\[UserName]\AppData\Local\Google\Chrome\User Data\ShaderCache\GPUCache to C:\Users\[UserName]\AppData\Local\Google\Chrome\User Data\ShaderCache\old_GPUCache_000
[14396:9608:0301/174908.329:ERROR:disk_cache.cc(184)] Unable to create cache
[14396:9608:0301/174908.333:ERROR:shader_disk_cache.cc(622)] Shader Cache Creation failed: -2
Traceback (most recent call last):
  File "create_new_account.py", line 105, in <module>
    browser = webdriver.Chrome(options=options)
  File "C:\Users\[UserName]\Anaconda3\envs\py37\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
  File "C:\Users\[UserName]\Anaconda3\envs\py37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 156, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\[UserName]\Anaconda3\envs\py37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 251, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\[UserName]\Anaconda3\envs\py37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
    self.error_handler.check_response(response)
  File "C:\Users\[UserName]\Anaconda3\envs\py37\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

【バージョン】
OS:Windows 7(64 ビット)
Python 3.7.0
Chrome:72.0.3626.119(64 ビット)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?