selenium icon indicating copy to clipboard operation
selenium copied to clipboard

[🐛 Bug]: Cannot create DevTools session twice - NPE thrown

Open kkoripl opened this issue 3 years ago • 3 comments

What happened?

With exact same driver I wanted to track requests comming through 2 pages. The thing was I wanted it to do as this:

  • Open page (driver.open()) and get tools (driver.getDevTools())
  • Create session (devtools.createSession()) alongside with (sending Network.enable(Optional.empty(), Optional.empty(), Optional.empty());
  • Add listener (devTools.addListener())
  • Listen
  • close devtools (devTools.close())
  • switch side (so repeat whole procedure)

The thing is, during the second iteration, there was NPE thrown from within Selenium code, saying that connection client was nullified. I thought that creating new session is possible after closing previous one, cause there was previous issue about it: https://github.com/SeleniumHQ/selenium/issues/11606.

How can we reproduce the issue?

public class NotWorkingTest {

    @Test
    public void notWorking() {
        ChromeDriverService.Builder builder = new ChromeDriverService.Builder();
        builder = builder.usingAnyFreePort();
        builder.usingDriverExecutable(new File("your path to chromedriver.exe"));
        ChromeDriverService chromeDriverService = builder.build();
        ChromeDriver chromeDriver = new ChromeDriver(chromeDriverService, new ChromeOptions());
        DevTools devTools = chromeDriver.getDevTools();

        devTools.createSession();
        devTools.close();

        devTools.createSession(); // stacktrace is here
        devTools.close();
    }
}

Relevant log output

java.lang.NullPointerException: Cannot invoke "java.net.http.HttpClient.newWebSocketBuilder()" because "this.client" is null

	at org.openqa.selenium.remote.http.jdk.JdkHttpClient.openSocket(JdkHttpClient.java:181)
	at org.openqa.selenium.devtools.Connection.reopen(Connection.java:93)
	at org.openqa.selenium.devtools.DevTools.createSession(DevTools.java:129)
	at org.openqa.selenium.devtools.DevTools.createSession(DevTools.java:117)

Operating System

Windows 10

Selenium version

Java 4.15.0

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

Chrome (but looks like any)

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

ChromeDriver 119.0.6045.105

Are you using Selenium Grid?

No response

kkoripl avatar Nov 16 '23 08:11 kkoripl

@kkoripl, 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!

github-actions[bot] avatar Nov 16 '23 08:11 github-actions[bot]

Thanks for reporting, this is a duplicate of #12882

titusfortner avatar Nov 16 '23 18:11 titusfortner

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Dec 17 '23 00:12 github-actions[bot]