Skip to content

[๐Ÿ› Bug]: Selenium SessionNotCreatedException: "User data directory is already in use" when running as root #15327

Closed
@ammarft-ai

Description

@ammarft-ai

What happened?

I am trying to launch a headless Chrome WebDriver using Selenium in Python. However, I keep encountering this error:

How can we reproduce the issue?

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

def createModel():
    service = Service(ChromeDriverManager().install())
    options = webdriver.ChromeOptions()
    
    # Specifying user data directory
    options.add_argument("--user-data-dir=/root/video-downloader/tmp/selenium-user-data")  
    options.add_argument("--headless=new")
    options.add_argument("--start-maximized")

    driver = webdriver.Chrome(service=service, options=options)
    return driver

driver = createModel()
driver.get("https://www.google.com")
print(driver.title)
driver.quit()

Relevant log output

selenium.common.exceptions.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

Operating System

Ubuntu

Selenium version

4.29.0

What are the browser(s) and version(s) where you see this issue?

Chrome

What are the browser driver(s) and version(s) where you see this issue?

Google Chrome 133.0.6943.126 ChromeDriver stable(auto)

Are you using Selenium Grid?

No response

Activity

added
I-defectSomething is not working as intended
A-needs-triagingA Selenium member will evaluate this soon!
on Feb 24, 2025
github-actions

github-actions commented on Feb 24, 2025

@github-actions

@ammarft-ai, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

diemol

diemol commented on Feb 24, 2025

@diemol
Member

I am not sure how we can help. You need to make sure the profile is not being used.

added
J-awaiting answerQuestion asked of user; a reply moves it to triage again
and removed
A-needs-triagingA Selenium member will evaluate this soon!
on Feb 24, 2025
cgoldberg

cgoldberg commented on Feb 25, 2025

@cgoldberg
Contributor

This could be caused by trying to access a profile that's already in use, or if the profile is not readable/writeable (yours seems to be owned by root?)

Either way, the error message is coming from chromedriver, so I don't think there is anything to fix from the selenium side.

added
A-needs-triagingA Selenium member will evaluate this soon!
and removed
J-awaiting answerQuestion asked of user; a reply moves it to triage again
on Feb 25, 2025
kiyotsu

kiyotsu commented on Feb 25, 2025

@kiyotsu

It also occurs in my environment.
I am running my tool with administrator privileges.
This error does not occur except when running as administrator.
I assume that an Edge version update triggers this error.

OS:Windows10
language:c#

thepbnk

thepbnk commented on Feb 25, 2025

@thepbnk

It also occurs in my environment. I am running my tool with administrator privileges. This error does not occur except when running as administrator. I assume that an Edge version update triggers this error.

OS:Windows10 language:c#

I don't know the cause, but I avoided the error by running msedgedriver.exe before initializing the driver.

  • Environment where it occurred
  • OS: Windows 10
  • c# Selenium Webdriver 4.2.0
  • msedge: 133.0.6943.127

static void Main()
        {
            string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string exeDirectory = Path.GetDirectoryName(exePath);
            String GetDrivePath = exeDirectory;
            String driverFileName = "msedgedriver.exe";


            EdgeDriverService eds = EdgeDriverService.CreateDefaultService(GetDrivePath, driverFileName);
            eds.HideCommandPromptWindow = true;
            eds.SuppressInitialDiagnosticInformation = true;

            StartProcessAsStandardUser(GetDrivePath + "\\" + driverFileName, eds.Port);

            System.Threading.Thread.Sleep(1000);
            EdgeOptions options = GetBrowserOption;
            string navigateUrl = "https://www.google.com";
            using (var driver = new EdgeDriver(eds, options))
            {
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(2);
                driver.Navigate().GoToUrl("about:blank");
                driver.Navigate().GoToUrl(navigateUrl);
            }
        }

public static void StartProcessAsStandardUser(string fileName, int port)
        {

            ProcessStartInfo psi = new ProcessStartInfo
            {
                FileName = "runas.exe",
                Arguments = $"/trustlevel:0x20000 \"{fileName} --port={port}\"",
                UseShellExecute = true,
                CreateNoWindow = true,
                WindowStyle = ProcessWindowStyle.Hidden
            };

            try
            {
                psi.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
                var proc = Process.Start(psi);
            }
            catch (Exception ex)
            {

            }
        }
cgoldberg

cgoldberg commented on Feb 26, 2025

@cgoldberg
Contributor

Try running chromdriver.exe from the command line, passing it the --user-data-dir argument and supplying the location of your profile. That will verify this is an issue with ChromeDriver and not selenium.

However, since the error is coming from ChromeDriver... this doesn't look like a selenium issue and it should reported to the ChromeDriver devs.

cgoldberg

cgoldberg commented on Feb 26, 2025

@cgoldberg
Contributor

@thepbnk

Why are you running as Admin?

Also, the reported issue was for Chrome, not Edge.

thepbnk

thepbnk commented on Feb 26, 2025

@thepbnk

@cgoldberg
Running it with administrator rights was a method I found while looking for a way to reproduce the error.

The PC where the error occurred did not have administrator rights, but it did occur. And I was able to avoid the error with this method.

Although it is a Chrome issue, I thought that a similar method could be used, so I left a comment.

VietND96

VietND96 commented on Feb 26, 2025

@VietND96
Member

I am running my tool with administrator privileges.
This error does not occur except when running as administrator.

If running as admin (in Windows) or with sudo (in Linux), can you try to pass browser arg --no-sandbox to see any help?
Refer to https://stackoverflow.com/a/70385974/14532601, #14609 (comment)

39 remaining items

VietND96

VietND96 commented on Mar 6, 2025

@VietND96
Member

@niceguy4, I saw your comment mentioned the issue when you ran test in the container, and fix by installing missing deps via apt install. I am not sure the browser pre-configure, but looks like you are using chrome-linux64.zip from chrome-for-testing, in package there is a file deb.deps with mention all deps needed for chrome can be launched, I think you can refer to that to keep container env install enough deps.

ssada1975

ssada1975 commented on Mar 6, 2025

@ssada1975

Same issue but it occurred when upgrading from 131 to upper version With the same parameters to launch cromedriver.
Isn't there any way to check what changed between 131 And 132 for example in chrome driver to find the solution ?

cgoldberg

cgoldberg commented on Mar 6, 2025

@cgoldberg
Contributor

Isn't there any way to check what changed between 131 And 132 for example in chrome driver to find the solution ?

@ssada1975

You'll have to take that up with chrome/chromedriver maintainers.

thos-grol

thos-grol commented on Mar 7, 2025

@thos-grol

@thos-grol When this occurred, were you running as Admin?

I was using admin. But with that option it now works even though I am using it.
In my past runs I was also using it too, so whatever change the edge driver creators made broke stuff.

niceguy4

niceguy4 commented on Mar 7, 2025

@niceguy4

@niceguy4, I saw your comment mentioned the issue when you ran test in the container, and fix by installing missing deps via apt install. I am not sure the browser pre-configure, but looks like you are using chrome-linux64.zip from chrome-for-testing, in package there is a file deb.deps with mention all deps needed for chrome can be launched, I think you can refer to that to keep container env install enough deps.

@VietND96 Thank you!

medsagou

medsagou commented on Mar 9, 2025

@medsagou

If you are using ubuntu bash, u have to run this commend before runing a selenium program
sudo apt install -y libxss1 libappindicator3-1 libindicator7
and add the folwoing arguments if you are using and ubuntu rdp:
options.add_argument("--no-sandbox") options.add_argument("--disable-dev-shm-usage")

titusfortner

titusfortner commented on Mar 20, 2025

@titusfortner
Member

For what it's worth I was also getting this recently with a new job I was running on GitHub Actions.
I fixed it by enabling this step to set xvfb and fluxbox: https://github.com/SeleniumHQ/selenium/blob/ffbfa024/.github/workflows/bazel.yml#L142-L148

Since this is not an issue that can be addressed by making changes in Selenium codebase, I'm going to close it. Thanks everyone for reporting and providing help. I'll include links below for getting additional help.

added
I-questionApplied to questions. Issues should be closed and send the user to community resources.
and removed
A-needs-triagingA Selenium member will evaluate this soon!
on Mar 20, 2025
github-actions

github-actions commented on Mar 20, 2025

@github-actions

๐Ÿ’ฌ Please ask questions at:

hafiz031

hafiz031 commented on Apr 8, 2025

@hafiz031

Also, make sure chromedriver is installed: chromedriver --version
If not install with: apt install chromium-chromedriver

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-defectSomething is not working as intendedI-questionApplied to questions. Issues should be closed and send the user to community resources.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

      Participants

      @stanislaw@titusfortner@cgoldberg@diemol@Venousek

      Issue actions

        [๐Ÿ› Bug]: Selenium SessionNotCreatedException: "User data directory is already in use" when running as root ยท Issue #15327 ยท SeleniumHQ/selenium