[Python] "User directory already in use" Selenium Python

Discussão em 'Python' iniciado por Stack, Abril 8, 2025.

  1. Stack

    Stack Membro Participativo

    I am aware that there are other questions like this one on the site, but I have found that they are trying to do a different thing and the solution is not applicable to my case. The issue is that I want to run a few instances of chrome simultaneously which works fine right now, but I would also like to save the data from each of the instances. To test this, I have run this minimal example:

    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service
    from selenium.webdriver.chrome.options import Options
    import os
    import time

    profile_path = os.path.join(os.getcwd(), f"chrome_profiles/{time.time()}")

    chrome_options = Options()
    chrome_options.add_argument(f"--user-data-dir={profile_path}")
    chrome_options.add_argument(f"--profile-directory=Default")


    service = Service()
    driver = webdriver.Chrome(service=service, options=chrome_options)

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


    This gives out the following error:

    SessionNotCreatedException: Message: session not created: probably user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir


    This is impossible since I literally used current time to create the user folder. But the folder gets created and then Chrome crashes. Mind you, I run only one instance.

    What is the issue here?

    Continue reading...

Compartilhe esta Página