When running the below simple example against Selenium 4.11, at some iteration in the loop the program will fail to get a new ChromeDriver instance with the following message:
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: DevToolsActivePort file doesn't exist
This is on Windows, so the common suggestion here doesn’t apply (but I did try it anyway): WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser
Below is a very simple test program that tries to check the Wikipedia logo multiple times in a loop.
Interestingly, this only seems to be a problem with ChromeDriver; if I use the EdgeDriver instead (see commented-out lines) all is well.
package example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeDriverService;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.manager.SeleniumManager;
import org.openqa.selenium.manager.SeleniumManagerOutput;
import java.io.File;
import java.io.IOException;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
public class SimpleTest
{
public static void main(String[] args) throws IOException
{
System.out.println("Initializing ChromeDriverService...");
ChromeOptions options = new ChromeOptions();
// EdgeOptions options = new EdgeOptions();
SeleniumManagerOutput.Result result = SeleniumManager.getInstance().getDriverPath(options, false);
String driverFile = result.getDriverPath();
System.out.println("Driver: " + driverFile);
ChromeDriverService driverService = new ChromeDriverService.Builder()
.usingDriverExecutable(new File(driverFile))
.withLogFile(new File("C:\\do\\chromedriver.log"))
.usingAnyFreePort()
.build();
// EdgeDriverService driverService = new EdgeDriverService.Builder()
// .usingDriverExecutable(new File(driverFile))
// .usingAnyFreePort()
// .build();
driverService.start();
System.out.println("DriverService initialized - " + driverService.getDriverName() + ", " + driverService.getDriverProperty());
for (int i = 0; i < 20; i++)
{
System.out.println("Iteration " + i + ": getting a webdriver");
ChromeDriver driver = new ChromeDriver(driverService, new ChromeOptions());
// EdgeDriver driver = new EdgeDriver(driverService, new EdgeOptions());
driver.manage().timeouts().implicitlyWait(Duration.of(3, ChronoUnit.SECONDS));
System.out.println("Iteration " + i + ": running test against webdriver");
driver.get("https://www.wikipedia.com");
WebElement logoImage = driver.findElement(By.cssSelector(".central-featured-logo")); // the main logo
System.out.println("Iteration " + i + ": logo src = " + logoImage.getAttribute("src"));
driver.close();
}
driverService.close();
}
}
It varies which particular iteration falls, but the furthest I’ve managed to get it to run was iteration 7.
The failure Exception is:
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: DevToolsActivePort file doesn't exist
Host info: host: 'REDACTED', ip: '192.168.1.124'
Build info: version: '4.11.0', revision: '040bc5406b'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_342'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*], extensions: []}}]}]
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:140)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:96)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:68)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)
at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:196)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:171)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:518)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:232)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:159)
at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:108)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:83)
at example.SimpleTest.main(SimpleTest.java:46)
Output from a sample run:
Initializing ChromeDriverService...
Driver: C:\Users\REDACTED\.cache\selenium\chromedriver\win64\115.0.5790.170\chromedriver.exe
DriverService initialized - chromedriver, webdriver.chrome.driver
Iteration 0: getting a webdriver
Iteration 0: running test against webdriver
Iteration 0: logo src = https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2.png
Iteration 1: getting a webdriver
Iteration 1: running test against webdriver
Iteration 1: logo src = https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2.png
Iteration 2: getting a webdriver
Iteration 2: running test against webdriver
Iteration 2: logo src = https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2.png
Iteration 3: getting a webdriver
Iteration 3: running test against webdriver
Iteration 3: logo src = https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2.png
Iteration 4: getting a webdriver
Iteration 4: running test against webdriver
Iteration 4: logo src = https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2.png
Iteration 5: running test against webdriver
Iteration 5: logo src = https://www.wikipedia.org/portal/wikipedia.org/assets/img/Wikipedia-logo-v2.png
Iteration 5: getting a webdriver
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: DevToolsActivePort file doesn't exist
Host info: host: 'REDACTED', ip: '192.168.1.124'
Build info: version: '4.11.0', revision: '040bc5406b'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_342'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--remote-allow-origins=*], extensions: []}}]}]
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:140)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:96)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:68)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)
at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:196)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:171)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:518)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:232)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:159)
at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:108)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:83)
at example.SimpleTest.main(SimpleTest.java:46)
This is on Windows 10 using Coretto 1.8.0_342, but switching to a newer JDK has made no difference. Chrome is on 115.0.5790.171 which at the time of writing is the most recent stable version.
For context: I’m battling with a Selenium 3 to 4.11 upgrade, and have reduced my issue to the simple PoC code above. I’m open to this being a user error (in fact I’d be glad if it is!) but I can’t see what I’ve done wrong
Yes, running more than 3 threads with ChromeDriver have some issues.
Possibly the issue is with ChromeDriver v115.0.5790.171
Instead of ChromeDriver v115.0.5790.171 try to download and use either among: