I'm trying to automate web tests with Selenium and Java in Ubuntu OS.
Earlier versions of Selenium used to work very well with older version of Firefox in Ubuntu.
Since I upgraded to
- Selenium 4+ (currently latest version 4.8.3) with
- FireFox 111.0.1 (64-bit) in
- Ubuntu 20.04.6 LTS
When I try to run this code:
public static void main(String[] args) {
try {
FirefoxDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
driver.get("https://www.google.com");
Thread.sleep(5000);
System.out.println(driver.getTitle());
driver.close();
} catch (Exception E) {
E.printStackTrace();
}
}
It results in this error:
1680156938202 geckodriver INFO Listening on 127.0.0.1:21408
1680156938676 mozrunner::runner INFO Running command: "/snap/firefox/current/firefox.launcher" "--marionette" "--remote-debugging-port" "14860" "--remote-allow-ho ... s" "http://127.0.0.1:14860/,http://localhost:14860/,http://[::1]:14860/" "-no-remote" "-profile" "/tmp/rust_mozprofile84ChAY"
org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: Failed to start browser /snap/firefox/current/firefox.launcher: no such file or directory
Host info: host: 'Aspire-ES1-571', ip: '127.0.1.1'
Build info: version: '4.8.3', revision: 'b19b418e60'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.0-69-generic', java.version: '17.0.5'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Command: [null, newSession {capabilities=[Capabilities {acceptInsecureCerts: true, browserName: firefox, moz:debuggerAddress: true, moz:firefoxOptions: {}}], desiredCapabilities=Capabilities {acceptInsecureCerts: true, browserName: firefox, moz:debuggerAddress: true, moz:firefoxOptions: {}}}]
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:148)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:106)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:165)
at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:183)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:229)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:150)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:146)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:131)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:127)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:112)
at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:102)
at Demo.demo.main(demo.java:17)
I tried to look up possible solution for this error on the internet. I did find a few similar issues and solutions for ChromeDriver
, but there is nothing related to 'FirefoxDriver'.
Can someone please help me resolve this?