SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
29.76k stars 8.02k forks source link

[🐛 Bug]: org.openqa.selenium.SessionNotCreatedException: Could not start a new session #14196

Closed smilinrobin closed 6 days ago

smilinrobin commented 1 week ago

What happened?

We are trying to run a simple script as attached and getting org.openqa.selenium.SessionNotCreatedException: Could not start a new session exception. The same script is working fine locally, but fails consistently on the Windows server 2022. Logs, environment details attached below: log Untitled image

How can we reproduce the issue?

Kindly run the GoogleSearch file with Selenium Java 4.20.0 on a Windows server 2022 edition. Reference here :


import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class GoogleSearch {
  public static void main(String[] args) {
    // Set the path to the chromedriver executable
    System.setProperty("webdriver.chrome.driver", "chromedriver.exe");

    // Create a new instance of the Chrome driver
    WebDriver driver = new ChromeDriver();

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

    // Find the search box element by name
    WebElement searchBox = driver.findElement(By.name("q"));

    // Type something to search for
    searchBox.sendKeys("Selenium Java");

    // Submit the form
    searchBox.submit();

    // Wait for the search results page to load
    // (You may need to add some waiting time or use explicit waits here)

    // Print the title of the search results page
    System.out.println("Page title is: " + driver.getTitle());

    // Close the browser
    driver.quit();
  }
}

Relevant log output

C: \Users \Centralsqtp\Downloads \selenium\SeleniumProject>java -cp ".;selenium-java-4.20.0\*; -" GoogleSearch Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible cause s are invalid address of the remote server or browser start-up failure.
Host info: host:
at org-openqa.selenium. remote.RemoteWebDriver.execute(RemoteWebDriver.java: 536)
at org-openqa.selenium. remote.RemoteWebDriver.startSession(RemoteWebDriver-java: 232) at org.openqa.selenium. remote.RemoteWebDriver. <init>(RemoteWebDriver.java:161)
at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver-java:114)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java: 88)
at org-openqa.selenium. chrome.ChromeDriver.<init>(ChromeDriver-java: 83) at org.openqa.selenium. chrome.ChromeDriver.<init>(ChromeDriver-java: 51)
at GoogleSearch.main(GoogleSearch.java: 12)
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to bind the port.
Build info: version: '4.20.0', revision: '866c76a80*
System info: os.name: "Windows Server 2022', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.22'
Driver info: driver-version: ChromeDriver
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:249)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:117)
at org.openqa.selenium.remote.RemoteWebDriver execute(RemoteWebDriver.java: 518)

Operating System

Microsoft Windows Server Version 21H2 (OS Build 20348.2402)

Selenium version

selenium-java-4.20.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?

ChromeDriver 125.0.6422.60

Are you using Selenium Grid?

No response

github-actions[bot] commented 1 week ago

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

krmahadevan commented 1 week ago

@smilinrobin - What happens when you get rid of this below line from your code and try again ?

System.setProperty("webdriver.chrome.driver", "chromedriver.exe");

Selenium internally uses the selenium manager to manager the correct version of the driver binaries that should be used for a given browser. So you don't need to be explicitly setting this up.

smilinrobin commented 1 week ago

Sure @krmahadevan . Will check and revert..

titusfortner commented 6 days ago

You would also need to opt in to that behavior with --selenium-manager true

titusfortner commented 6 days ago

yeah, this needs to be the full path to the driver: System.setProperty("webdriver.chrome.driver", "chromedriver.exe")

So, opting in to use selenium manager with detect drivers would fix it as well.