[Python] Cannot use local user data for Chrome while running Selenium

Discussão em 'Python' iniciado por Stack, Junho 1, 2025.

  1. Stack

    Stack Membro Participativo

    I am running python program with Selenium to automate browser page processing. In order to open the pages correctly, I need to use my login and password saved in the Chrome user profile for my website. I created a new Chrome profile for that purpose. However, the program cannot read my user profile data for some reason. Here is the start of my python program:

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    import time, os

    CHROME_USER_DIR = "C:/Users/LocalUserName/AppData/Local/Google/Chrome/User Data"
    PROFILE_NAME = "Profile 1"

    options = Options()
    options.add_argument(f"--user-data-dir={CHROME_USER_DIR}")
    options.add_argument(f"--profile-directory={PROFILE_NAME}")
    driver = webdriver.Chrome(options=options)


    I get the following error:

    DevTools remote debugging requires a non-default data directory. Specify this using --user-data-dir.
    [12252:10400:0601/205536.845:ERROR:gpu\ipc\service\gpu_channel_manager.cc:946] Failed to create GLES3 context, fallback to GLES2.
    [12252:10400:0601/205536.845:ERROR:gpu\ipc\service\gpu_channel_manager.cc:957] ContextResult::kFatalFailure: Failed to create shared context for virtualization.
    [12252:10400:0601/205536.960:ERROR:gpu\ipc\service\gpu_channel_manager.cc:946] Failed to create GLES3 context, fallback to GLES2.
    [12252:10400:0601/205536.960:ERROR:gpu\ipc\service\gpu_channel_manager.cc:957] ContextResult::kFatalFailure: Failed to create shared context for virtualization.
    [12252:10400:0601/205536.960:ERROR:gpu\ipc\service\gpu_channel_manager.cc:946] Failed to create GLES3 context, fallback to GLES2.
    [12252:10400:0601/205536.960:ERROR:gpu\ipc\service\gpu_channel_manager.cc:957] ContextResult::kFatalFailure: Failed to create shared context for virtualization.
    [6180:10560:0601/205539.087:ERROR:chrome\browser\policy\cloud\fm_registration_token_uploader.cc:179] Client is missing for kUser scope
    WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
    I0000 00:00:1748800539.099043 2104 voice_transcription.cc:58] Registering VoiceTranscriptionCapability
    Created TensorFlow Lite XNNPACK delegate for CPU.
    [6180:5096:0601/205539.234:ERROR:google_apis\gcm\engine\registration_request.cc:291] Registration response error message: DEPRECATED_ENDPOINT
    [6180:1708:0601/205539.382:ERROR:components\system_cpu\cpu_probe_win.cc:112] PdhAddEnglishCounter failed for '\Processor(_Total)\% Processor Time': Error (0x13D) while retrieving error. (0xC0000BB8)
    [6180:1864:0601/205539.382:ERROR:components\system_cpu\cpu_probe_win.cc:112] PdhAddEnglishCounter failed for '\Processor(_Total)\% Processor Time': Error (0x13D) while retrieving error. (0xC0000BB8)
    [6180:1708:0601/205551.758:ERROR:components\system_cpu\cpu_probe_win.cc:112] PdhAddEnglishCounter failed for '\Processor(_Total)\% Processor Time': Error (0x13D) while retrieving error. (0xC0000BB8)
    [6180:5096:0601/205605.808:ERROR:google_apis\gcm\engine\registration_request.cc:291] Registration response error message: DEPRECATED_ENDPOINT
    [6180:1708:0601/205606.768:ERROR:components\system_cpu\cpu_probe_win.cc:112] PdhAddEnglishCounter failed for '\Processor(_Total)\% Processor Time': Error (0x13D) while retrieving error. (0xC0000BB8)
    [6180:1708:0601/205621.778:ERROR:components\system_cpu\cpu_probe_win.cc:112] PdhAddEnglishCounter failed for '\Processor(_Total)\% Processor Time': Error (0x13D) while retrieving error. (0xC0000BB8)
    [6180:1708:0601/205636.778:ERROR:components\system_cpu\cpu_probe_win.cc:112] PdhAddEnglishCounter failed for '\Processor(_Total)\% Processor Time': Error (0x13D) while retrieving error. (0xC0000BB8)
    Traceback (most recent call last):
    File "D:\Work\script_runner.py", line 38, in <module>
    driver = webdriver.Chrome(options=options)
    File "C:\Users\LocalUserName\AppData\Local\Programs\Python\Python313\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 47, in __init__
    super().__init__(
    ~~~~~~~~~~~~~~~~^
    browser_name=DesiredCapabilities.CHROME["browserName"],
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
    keep_alive=keep_alive,
    ^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
    File "C:\Users\LocalUserName\AppData\Local\Programs\Python\Python313\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 69, in __init__
    super().__init__(command_executor=executor, options=options)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\LocalUserName\AppData\Local\Programs\Python\Python313\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 257, in __init__
    self.start_session(capabilities)
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
    File "C:\Users\LocalUserName\AppData\Local\Programs\Python\Python313\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 356, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\LocalUserName\AppData\Local\Programs\Python\Python313\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 447, in execute
    self.error_handler.check_response(response)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
    File "C:\Users\LocalUserName\AppData\Local\Programs\Python\Python313\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 232, in check_response
    raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.SessionNotCreatedException: Message: session not created
    from chrome not reachable
    Stacktrace:
    GetHandleVerifier [0x0x7ff7c0f26f65+78965]
    GetHandleVerifier [0x0x7ff7c0f26fc0+79056]
    (No symbol) [0x0x7ff7c0cb9c0c]
    (No symbol) [0x0x7ff7c0caaa41]
    (No symbol) [0x0x7ff7c0cfceb2]
    (No symbol) [0x0x7ff7c0cf7a78]
    (No symbol) [0x0x7ff7c0cf297d]
    (No symbol) [0x0x7ff7c0d465be]
    (No symbol) [0x0x7ff7c0d45d50]
    (No symbol) [0x0x7ff7c0d38443]
    (No symbol) [0x0x7ff7c0d01311]
    (No symbol) [0x0x7ff7c0d020a3]
    GetHandleVerifier [0x0x7ff7c11de26d+2926461]
    GetHandleVerifier [0x0x7ff7c11d8993+2903715]
    GetHandleVerifier [0x0x7ff7c11f6aed+3026941]
    GetHandleVerifier [0x0x7ff7c0f416fe+187406]
    GetHandleVerifier [0x0x7ff7c0f496ef+220159]
    GetHandleVerifier [0x0x7ff7c0f2faf4+114692]
    GetHandleVerifier [0x0x7ff7c0f2fca9+115129]
    GetHandleVerifier [0x0x7ff7c0f164d8+10728]
    BaseThreadInitThunk [0x0x7ff82e307374+20]
    RtlUserThreadStart [0x0x7ff82f9dcc91+33]


    Note that when I run the same program without the lines:

    options.add_argument(f"--user-data-dir={CHROME_USER_DIR}")
    options.add_argument(f"--profile-directory={PROFILE_NAME}")


    The program runs correctly, except the website is not displaying the gage correctly as it did not log in with my username/password.

    I already checked the following: ChromeDriver and Chrome have the same version. I do not use any other apps with my Chrome profile while running the program.

    Any ideas what goes wrong and how to fix it?

    Continue reading...

Compartilhe esta Página