Java - Selenium 4.18.1: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure

323 views Asked by At

Selenium recently updated its way of using web drivers. (I have prior experience with selenium version 4.9.0 in python where we just downloaded the web driver and used it by driver = webdriver.Edge(service=Service(path_to_webdriver)) but in new documentation I see no trace of it left) And now I got stuck that how can I use it. I've searched the documentation and other threads in Stackoverflow but could not start a new session with this simple code:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;

public class Main {
    public static void main(String[] args) {
        System.setProperty("webdriver.edge.driver", "PATH TO WEB DRIVER");

        WebDriver driver = new EdgeDriver();

        driver.get("https://www.selenium.dev/selenium/web/web-form.html");
        
        driver.quit();
   }
}

This gives org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.

I updated my Microsoft Edge and its web driver to the latest version, And tried not to use System.setProperty like the code example from documentation (even copied the whole example from this address). Still no progress. What could possibly go wrong here?

EDIT: I forgot to mention, Edge isn't launching. That's the main problem probably. The program doesn't know how to launch Edge. I tried changing to Firefox browser but that didn't work out too.

EDIT2: Full stack trace:

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. 
Host info: host: 'myuser', ip: '192.168.56.1'
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:537)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:233)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:162)
    at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:114)
    at org.openqa.selenium.edge.EdgeDriver.<init>(EdgeDriver.java:61)
    at org.openqa.selenium.edge.EdgeDriver.<init>(EdgeDriver.java:57)
    at org.openqa.selenium.edge.EdgeDriver.<init>(EdgeDriver.java:49)
    at org.openqa.selenium.edge.EdgeDriver.<init>(EdgeDriver.java:45)
    at com.aut.CoursesGrabber.main(CoursesGrabber.java:19)
Caused by: org.openqa.selenium.WebDriverException: Driver server process died prematurely.
Build info: version: '4.18.1', revision: 'b1d3319b48'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '20'
Driver info: driver.version: EdgeDriver
    at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:246)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:117)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:519)
1

There are 1 answers

0
hfontanez On

This worked for me. To get it to work, I downloaded the stable version of the MS Edge Web Driver from here. I believe there is a security setting that was added after version 114 where you need to add that option (--remote-allow-origins=*). For me, without adding this, I could not get neither Edge or Chrome to work. I kept getting a 403 error. This makes sense since both browsers are build on the Chromium platform. If this code does not work for you, I assume there is something corrupted in your environment. From the console, you can see I am using Selenium 4.1.2.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;

public class Main {
    public static void main(String[] args) {
        System.setProperty("webdriver.edge.driver", "f:/webdrivers/msedgedriver.exe");

        EdgeOptions options = new EdgeOptions();
        options.addArguments("--remote-allow-origins=*");
        WebDriver driver = new EdgeDriver(options);
        driver.get("https://www.selenium.dev/selenium/web/web-form.html");
        driver.quit();
    }
}

My console shows

Starting Microsoft Edge WebDriver 122.0.2365.80 (bfff41c27eb2a14d912253b34105302b913913cf) on port 57515
To submit feedback, report a bug, or suggest new features, please visit https://github.com/MicrosoftEdge/EdgeWebDriver

Only local connections are allowed.
Please see https://aka.ms/WebDriverSecurity for suggestions on keeping Microsoft Edge WebDriver safe.

Microsoft Edge WebDriver was started successfully.
Mar 09, 2024 11:23:10 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Mar 09, 2024 11:23:10 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
WARNING: Unable to find an exact match for CDP version 122, so returning the closest version found: a no-op implementation
Mar 09, 2024 11:23:10 AM org.openqa.selenium.devtools.CdpVersionFinder findNearestMatch
INFO: Unable to find CDP implementation matching 122.
Mar 09, 2024 11:23:10 AM org.openqa.selenium.chromium.ChromiumDriver lambda$new$3
WARNING: Unable to find version of CDP to use for . You may need to include a dependency on a specific version of the CDP using something similar to `org.seleniumhq.selenium:selenium-devtools-v86:4.1.2` where the version ("v86") matches the version of the chromium-based browser you're using and the version number of the artifact is the same as Selenium's.

Process finished with exit code 0