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:
- Created 2 years ago
- Comments:10 (4 by maintainers)
Top GitHub Comments
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.
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.