Skip to content

[🐛 Bug]: SessionNotCreatedException with unique --user-data-dir when running JAR via EXE on Windows #15967

@ytuskan

Description

@ytuskan

Description

Bug Description

When launching a Selenium test with ChromeDriver and passing a unique --user-data-dir path (generated via UUID), I still get the following error:

org.openqa.selenium.SessionNotCreatedException: 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

Environment

  • OS: Windows 10 x64
  • Chrome version: 138.0.7204.50
  • ChromeDriver version: 138.x (manually matched)
  • Java version: 1.8.0_251
  • Selenium: 4.33.0
  • Execution context: A .jar file launched from a .exe wrapper using ProcessStartInfo.Verb = "runas" (admin mode)

Code Sample

Path profileDir = Paths.get("C:\\Temp\\selenium_profile_" + UUID.randomUUID());
Files.createDirectories(profileDir);

ChromeOptions options = new ChromeOptions();
options.addArguments("--user-data-dir=" + profileDir.toAbsolutePath().toString());

WebDriver driver = new ChromeDriver(options);

Notes
-The profile directory is unique on every run.
-No other processes are accessing or reusing the directory.
-This error only happens when the JAR is launched via an EXE.
-When running the same code directly via java -jar myapp.jar, it works fine.

Question
Why does ChromeDriver still throw SessionNotCreatedException with a fresh --user-data-dir only when the JAR is executed from an EXE?

Is this a known issue on Windows when running in elevated mode?

Thanks in advance.


### Reproducible Code

```shell
private static WebDriver getChromeWebDriver(boolean isHeadless) throws Exception {
        String chromeVersionStr = getBrowserVersionUsingProperties();
        int chromeVersion = extractVersion(chromeVersionStr);

        if (chromeVersion < 115)
            WebDriverManager.chromedriver().setup();
        else {
            OsEnum os = OsEnum.getOs();
            String newExePath = System.getProperty("user.home") + File.separator + ".cache" + File.separator
                    + "selenium" + File.separator + "chromedriver" + File.separator + os.getChromeDriverKey()
                    + File.separator + chromeVersionStr;

            if (!FileUtil.fileExists(newExePath + File.separator + os.getChromeDriverName())) {
                String chromeDownloadLink = downloadLatestVersionOfChromeDriverGetURLToDownload(chromeVersionStr
                        , os.getChromeDriverKey());
                killAllDrivers("CHROME");

                downloadChromeDriverToPath(chromeDownloadLink, newExePath);
            }

            System.setProperty("webdriver.chrome.driver", newExePath + File.separator + os.getChromeDriverName());
        }

        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("--ignore-certificate-errors");
        chromeOptions.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));

        Path newSlnTempPath = Paths.get(CONNECTOR_TEMP_FOLDER + "selenium_chrome_profile" + File.separator + UUID.randomUUID());
        Files.createDirectories(newSlnTempPath);

        chromeOptions.addArguments("--user-data-dir=" + newSlnTempPath.toAbsolutePath());

        if (isHeadless) {
            chromeOptions.setHeadless(true);
            chromeOptions.addArguments("--window-position=-32000,-32000");
        }

        return new ChromeDriver(chromeOptions);
    }

Debugging Logs

2025-06-26 17:28:06.338 �[34mINFO �[0;39m c.a.c.c.u.SeleniumUtils.getChromeWebDriver - chromeOptions hata: 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
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'YTUSKAN', ip: '10.212.134.201', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_251'
Driver info: driver.version: ChromeDriver
remote stacktrace: 	GetHandleVerifier [0x0x644493+62419]
	GetHandleVerifier [0x0x6444d4+62484]
	(No symbol) [0x0x482133]
	(No symbol) [0x0x4b5958]
	(No symbol) [0x0x4b1249]
	(No symbol) [0x0x4faf3e]
	(No symbol) [0x0x4fa82a]
	(No symbol) [0x0x4ef266]
	(No symbol) [0x0x4be852]
	(No symbol) [0x0x4bf6f4]
	GetHandleVerifier [0x0x8b4773+2619059]
	GetHandleVerifier [0x0x8afb8a+2599626]
	GetHandleVerifier [0x0x66b03a+221050]
	GetHandleVerifier [0x0x65b2b8+156152]
	GetHandleVerifier [0x0x661c6d+183213]
	GetHandleVerifier [0x0x64c378+94904]
	GetHandleVerifier [0x0x64c502+95298]
	GetHandleVerifier [0x0x63765a+9626]
	BaseThreadInitThunk [0x0x76cefcc9+25]
	RtlGetAppContainerNamedObjectPath [0x0x77e782ae+286]
	RtlGetAppContainerNamedObjectPath [0x0x77e7827e+238]

org.openqa.selenium.SessionNotCreatedException: 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
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'YTUSKAN', ip: '10.212.134.201', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_251'
Driver info: driver.version: ChromeDriver
remote stacktrace: 	GetHandleVerifier [0x0x644493+62419]
	GetHandleVerifier [0x0x6444d4+62484]
	(No symbol) [0x0x482133]
	(No symbol) [0x0x4b5958]
	(No symbol) [0x0x4b1249]
	(No symbol) [0x0x4faf3e]
	(No symbol) [0x0x4fa82a]
	(No symbol) [0x0x4ef266]
	(No symbol) [0x0x4be852]
	(No symbol) [0x0x4bf6f4]
	GetHandleVerifier [0x0x8b4773+2619059]
	GetHandleVerifier [0x0x8afb8a+2599626]
	GetHandleVerifier [0x0x66b03a+221050]
	GetHandleVerifier [0x0x65b2b8+156152]
	GetHandleVerifier [0x0x661c6d+183213]
	GetHandleVerifier [0x0x64c378+94904]
	GetHandleVerifier [0x0x64c502+95298]
	GetHandleVerifier [0x0x63765a+9626]
	BaseThreadInitThunk [0x0x76cefcc9+25]
	RtlGetAppContainerNamedObjectPath [0x0x77e782ae+286]
	RtlGetAppContainerNamedObjectPath [0x0x77e7827e+238]

	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_251]
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_251]
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_251]
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_251]
	at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62) ~[selenium-remote-driver-3.141.59.jar!/:na]
	at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30) ~[selenium-remote-driver-3.141.59.jar!/:na]
	at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126) ~[selenium-remote-driver-3.141.59.jar!/:na]
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_251]
	at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958) ~[na:1.8.0_251]
	at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126) ~[na:1.8.0_251]
	at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:499) ~[na:1.8.0_251]
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:486) ~[na:1.8.0_251]
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) ~[na:1.8.0_251]
	at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152) ~[na:1.8.0_251]
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_251]
	at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464) ~[na:1.8.0_251]
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128) ~[selenium-remote-driver-3.141.59.jar!/:na]
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74) ~[selenium-remote-driver-3.141.59.jar!/:na]
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136) ~[selenium-remote-driver-3.141.59.jar!/:na]
	at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) ~[selenium-remote-driver-3.141.59.jar!/:na]
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552) ~[selenium-remote-driver-3.141.59.jar!/:na]
	at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213) ~[selenium-remote-driver-3.141.59.jar!/:na]
	at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131) ~[selenium-remote-driver-3.141.59.jar!/:na]
	at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181) ~[selenium-chrome-driver-3.141.59.jar!/:na]
	at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168) ~[selenium-chrome-driver-3.141.59.jar!/:na]
	at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:157) ~[selenium-chrome-driver-3.141.59.jar!/:na]
	at com.altospace.cloud.commons.utils.SeleniumUtils.getChromeWebDriver(SeleniumUtils.java:889) [assistant-public-operations-0.0.1-SNAPSHOT.jar!/:0.0.1-SNAPSHOT]
	at com.altospace.cloud.commons.utils.SeleniumUtils.getDriver(SeleniumUtils.java:665) [assistant-public-operations-0.0.1-SNAPSHOT.jar!/:0.0.1-SNAPSHOT]
	at com.altospace.cloud.commons.utils.SeleniumUtils.setDriver(SeleniumUtils.java:103) [assistant-public-operations-0.0.1-SNAPSHOT.jar!/:0.0.1-SNAPSHOT]
	at com.altospace.cloud.commons.utils.SeleniumUtils.setDriver(SeleniumUtils.java:94) [assistant-public-operations-0.0.1-SNAPSHOT.jar!/:0.0.1-SNAPSHOT]
	at com.mikrokom.mikrokomyardimci.service.selenium.DigitalGibService.loginDigitalGib(DigitalGibService.java:175) [classes!/:1.0.0]
	at com.mikrokom.mikrokomyardimci.controller.selenium.DigitalVDController.mukellefDigitalVD(DigitalVDController.java:36) [classes!/:1.0.0]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_251]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_251]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_251]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_251]
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:197) [spring-web-5.3.7.jar!/:5.3.7]
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:141) [spring-web-5.3.7.jar!/:5.3.7]
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106) [spring-webmvc-5.3.7.jar!/:5.3.7]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:894) [spring-webmvc-5.3.7.jar!/:5.3.7]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) [spring-webmvc-5.3.7.jar!/:5.3.7]
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) [spring-webmvc-5.3.7.jar!/:5.3.7]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1063) [spring-webmvc-5.3.7.jar!/:5.3.7]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) [spring-webmvc-5.3.7.jar!/:5.3.7]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) [spring-webmvc-5.3.7.jar!/:5.3.7]
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) [spring-webmvc-5.3.7.jar!/:5.3.7]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:652) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) [spring-webmvc-5.3.7.jar!/:5.3.7]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) [tomcat-embed-websocket-9.0.46.jar!/:na]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) [spring-web-5.3.7.jar!/:5.3.7]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.3.7.jar!/:5.3.7]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) [spring-web-5.3.7.jar!/:5.3.7]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.3.7.jar!/:5.3.7]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) [spring-web-5.3.7.jar!/:5.3.7]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) [spring-web-5.3.7.jar!/:5.3.7]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1707) [tomcat-embed-core-9.0.46.jar!/:na]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.46.jar!/:na]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_251]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_251]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.46.jar!/:na]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_251]

ℹ️ Last known working version: 4.33.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-javaJava BindingsD-chromeG-chromedriverRequires fixes in ChromeDriverI-defectSomething is not working as intendedI-regressionSomething was working but we "fixed" itOS-windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions