3

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?

1

1 Answer 1

1

This is a bug in GeckoDriver (fixed in Selenium 4.16.1 or earlier).

To avoid changes in the code, upgrade or apply a workaround of creating a symbolic link:

sudo mkdir -p /snap/firefox/current
sudo ln -s /usr/bin/firefox /snap/firefox/current/
sudo mv /snap/firefox/current/firefox /snap/firefox/current/firefox.launcher

(-p is for creating all non-existing directories on the way, -s is for symbolic link and the last line is needed because the names of both executables differ)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.