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)
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.
My console shows