@natsuki0104

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

【python】Selenium (Chrome) でgoogleアカウントにProfileを使用してログインしようとするとエラーが発生

解決したいこと

【python】Selenium (Chrome) でgoogleアカウントにProfileを使用してログインしたい

プログラミング初心者です。
seleniumでgoogleにログインするにはプロファイルを使用する必要があることを知りました。
chrome://version からパスを取得し、コードに記述したのですが以下のようなエラーが発生します。

発生している問題・エラー

Traceback (most recent call last):
  File "d:\デスクトップ\VScode\from selenium.webdriver.chrome.py", line 22, in <module>
    driver = gl('https://drive.google.com/drive/my-drive?hl=ja') 
  File "d:\デスクトップ\VScode\from selenium.webdriver.chrome.py", line 19, in gl
    driver = webdriver.Chrome(options=option)
  File "C:\Users\turni\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__  
    super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "C:\Users\turni\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 92, in __init__
    super().__init__(
  File "C:\Users\turni\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 277, in __init__ 
    self.start_session(capabilities, browser_profile)
  File "C:\Users\turni\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 370, in start_session  
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\turni\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 435, in execute        
    self.error_handler.check_response(response)
  File "C:\Users\turni\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
Backtrace:
        GetHandleVerifier [0x00E38893+48451]
        (No symbol) [0x00DCB8A1]
        (No symbol) [0x00CD5058]
        (No symbol) [0x00CF3211]
        (No symbol) [0x00CF0019]
        (No symbol) [0x00D20798]
        (No symbol) [0x00D2047C]
        (No symbol) [0x00D1A0B6]
        (No symbol) [0x00CF7E08]
        (No symbol) [0x00CF8F2D]
        GetHandleVerifier [0x01098E3A+2540266]
        GetHandleVerifier [0x010D8959+2801161]
        GetHandleVerifier [0x010D295C+2776588]
        GetHandleVerifier [0x00EC2280+612144]
        (No symbol) [0x00DD4F6C]
        (No symbol) [0x00DD11D8]
        (No symbol) [0x00DD12BB]
        (No symbol) [0x00DC4857]
        BaseThreadInitThunk [0x764F0099+25]
        RtlGetAppContainerNamedObjectPath [0x774A7B6E+286]
        RtlGetAppContainerNamedObjectPath [0x774A7B3E+238]

該当するソースコード

option = Options()
option.add_argument('--disable-features=RendererCodeIntegrity')
option.add_argument('--user-data-dir=C:\\Users\\name\\AppData\\Local\\Google\\Chrome\\User Data')
option.add_argument('--profile-directory=Profile 5')
driver = webdriver.Chrome(options=option)
driver.get('https://drive.google.com/drive/my-drive?hl=ja')

自分で試したこと

C#で全く同じことをしても同じようなエラーになりました。

補足情報

OS:Windows10
Chrome : 113.0.5672.2400
Selenium.Webdriver : 4.7.0

0 likes

1Answer

option.add_argumentはなくともfirefox以外は動作しますよ!

option = Options()
webdriver.Chrome(options=option)
0Like

Comments

  1. @natsuki0104

    Questioner

    seleniumでchromeにgoogleアカウントでログインするにはプロファイルが必要ですよね?

  2. googleアカウントにProfileを使用しないでログインしたいつまり、他のサイトには接続できるコードを転用してはトライしているでよろしいでしょうか?

    linuxの例でですみません。ご参考に

  3. @natsuki0104

    Questioner

    ごめんなさい、ちょっと理解ができていません。
    "googleアカウントにprofileを使用しないでログインしたい"とは言っていなくて、手段はどうであれgoogleアカウントを使用できる方法を探っています。
    アカウントを使用する手段としてprofileが必要ではないということでしょうか?
    そのような手段があればご教授お願いします。
    profileを使用する手段は既に試していてその結果エラーが発生したといった現状です。

  4. すみません。言葉たらずでした。
     昔はできましたよ!googleの仕様が変わったとして、先ずは、プロファイル設定無しで、seleniumでログインできる工程を説明しないと、コードの記述なしで、その先に進めないのではないのではないでしょうか。
     
    profileを使用する手段は既に試していてその結果エラーが発生した

    つまり、今はできないと判断したなら、別の考え方を提示する必要があると思います。

  5. @natsuki0104

    Questioner

    既に起動してあるchromeを閉じたらプロファイルを使用することができました。
    回答ありがとうございました!

Your answer might help someone💌