question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FirefoxDriver crashes in toExecutor() method

See original GitHub issue

🐛 Bug Report

I got the following error when executing my project from the command line whereas it works properly in the IDE (IntelliJ).

Exception in thread “main” org.openqa.selenium.WebDriverException: Build info: version: ‘4.0.0-rc-3’, revision: ‘5fe1af712f’ System info: host: ‘xxxx’, ip: ‘1.2.3.4’, os.name: ‘Linux’, os.arch: ‘amd64’, os.version: ‘5.10.0-kali9-amd64’, java.version: ‘11.0.12’ Driver info: driver.version: FirefoxDriver at java.base/java.util.Optional.orElseThrow(Optional.java:408) at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:230) at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:186) at company.GeckodriverTest.createFirefoxWebDriver(GeckodriverTest.java:53) at company.GeckodriverTest.run(GeckodriverTest.java:22) at company.GeckodriverTest.main(GeckodriverTest.java:17)

To Reproduce

I created a simple maven project to demonstrate the problem (see Java code and pom.xml below).

Project | |_src/main/java/company/GeckodriverTest.java | |_webdriver/geckodriver | |_target/artifact-1.0.0-SNAPSHOT.jar

GeckodriverTest.java

package company;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxDriverLogLevel;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class GeckodriverTest {
    private WebDriver driver;

    public static void main(String[] args) {
        new GeckodriverTest().run();
    }

    private void run() {
        driver = createFirefoxWebDriver();
        driver.get("https://duckduckgo.com");
        set(By.id("search_form_input_homepage"), "selenium");
        click(By.id("search_button_homepage"));
        driver.close();
    }

    private void set(By by, String content) {
        this.findElement(by).sendKeys(new CharSequence[]{content});
    }

    private void click(By by) {
        this.waitForElement(ExpectedConditions.elementToBeClickable(by));
        this.findElement(by).click();
    }

    private WebElement findElement(By by) {
        this.waitForElement(ExpectedConditions.presenceOfElementLocated(by));
        return driver.findElement(by);
    }

    private void waitForElement(ExpectedCondition<WebElement> cond) {
        (new WebDriverWait(driver, 30L)).until(cond);
    }

    private WebDriver createFirefoxWebDriver() {
        System.setProperty("webdriver.gecko.driver", "./webdriver/geckodriver");
        System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "./gecko.log");
        FirefoxOptions options = new FirefoxOptions();
        options.setHeadless(false);
        options.setLogLevel(FirefoxDriverLogLevel.TRACE);
        return new FirefoxDriver(options);
    }
}

pom.xml

<?xml version="1.0" encoding="UTF-8">
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>company</groupId>
    <artifactId>artifact</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <selenium.version>4.0.0-rc-3</selenium.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>

                <executions>
                    <execution>
                        <id>jar</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <archive>
                                <manifest>
                                    <mainClass>company.GeckodriverTest</mainClass>
                                </manifest>
                            </archive>
                            <appendAssemblyId>false</appendAssemblyId>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.version}</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-api</artifactId>
            <version>${selenium.version}</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-remote-driver</artifactId>
            <version>${selenium.version}</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-firefox-driver</artifactId>
            <version>${selenium.version}</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-support</artifactId>
            <version>${selenium.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-exec</artifactId>
            <version>1.3</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>31.0.1-jre</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.8</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.13</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.4.14</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.14.1</version>
        </dependency>
    </dependencies>
</project>

Expected behavior

I expect that the Firefox browser is launched, as when executed from the IDE.

Test script or set of commands reproducing this issue

Run java -jar target/artifact-1.0.0-SNAPSHOT.jar

Environment

OS: Linux Browser: Firefox Browser version: 78.14.0esr (64 bits) Browser Driver version: 0.30.0 Language Bindings version: Java 11.0.12

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jlucbtcommented, Oct 18, 2021

I manage to find out where the problem was. It was not a problem with the path.

As you proabably know, at runtime, available driver services (e.g. GeckoDriverService, ChromeDriverService, etc.) are detected based on the content of a file named “org.openqa.selenium.remote.service.DriverService$Builder” that is located in the jar under the /META-INF/services/ path. It contains the names of the concrete available driver services.

When I examined the content of this file in my jar it contained only this single line : org.openqa.selenium.chrome.ChromeDriverService$Builder

So, only the chrome service was available at runtime.

I found 2 ways of fixing it.

1st solution

I added the following file to my project that overrides the default one put in the jar :

Project |_src/resources/META-INF/sources/org.openqa.selenium.remote.service.DriverService$Builder

With the following content : org.openqa.selenium.firefox.GeckoDriverService$Builder

I rebuild the jar and everything works fine now.

2nd solution In the pom.xml, I moved up the “<artifactId>selenium-firefox-driver</artifactId>” dependency to the top of the dependencies, like that :

<dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-firefox-driver</artifactId> <version>${selenium.version}</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>${selenium.version}</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-api</artifactId> <version>${selenium.version}</version> </dependency>

etc.

And it works well.

If it’s witten as below (as it was previously), then it’s the chrome service that ends up in the “org.openqa.selenium.remote.service.DriverService$Builder” file. I actually don’t know why but I checked several times to make it sure.

<dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>${selenium.version}</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-firefox-driver</artifactId> <version>${selenium.version}</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-api</artifactId> <version>${selenium.version}</version> </dependency>

This doesn’t work.


De : Diego Molina @.> Envoyé : mercredi 13 octobre 2021 10:51 À : SeleniumHQ/selenium @.> Cc : Jean-Luc BARRILLOT @.>; Author @.> Objet : Re: [SeleniumHQ/selenium] FirefoxDriver crashes in toExecutor() method (#9907)

Environment in the IDE and the jar itself are different.

If you want, provide a GitHub repo with the code and we can have a look, and then I will reopen this issue.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/SeleniumHQ/selenium/issues/9907#issuecomment-942076969, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AWBEZKGA367ADRJEF5P2U5TUGVCARANCNFSM5F4PUCXQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

1reaction
rockidudecommented, Oct 18, 2021

We got the same problem in our project. The last comment describes a workaround, but shouldn’t be the prefered solution here. Why is this ticket closed. In my opinion it should be opened again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firefox crashes when started by Selenium firefox driver
driver = new FirefoxDriver();. but there are a error. Problem Event Name: APPCRASH Application Name: firefox.exe Application Version: 38.0.
Read more >
How To Launch Firefox in Selenium using GeckoDriver
hello , i tried opening facebook via firefox driver. with the below code : System.setProperty(“webdriver.firefox.marionette”,”C:\\Users\\Admin\\ ...
Read more >
Firefox crashes after starting Manual Explore - Google Groups
Hi, can you check why Firefox crashes after starting Manual Explore. ... toExecutor(FirefoxDriver.java:187) ~[selenium-release-15.4.0.zap:?].
Read more >
Handling exceptions and browser crashes in Selenium
Browsers crash and the internet sometimes doesn't work, ... and have the browser restart part way through the scrape job after a crash....
Read more >
Analyzing crash data of Firefox - Firefox Source Docs
That also means that if Firefox crashed the created minidump files are lost. ... "/Applications/Firefox.app/Contents/MacOS/firefox" driver = webdriver.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found