How to use the gecko executable with Selenium
Recently Selenium has launched Selenium 3 and if you are trying to use Firefox latest version then you have to use GeckoDriver:
System.setProperty("webdriver.gecko.driver","G:\\Selenium\\Firefox driver\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
You can check full documentation from here
I am also facing the same issue and got the resolution after a day :
The exception is coming because System needs Geckodriver to run the Selenium test case. You can try this code under the main Method in Java
System.setProperty("webdriver.gecko.driver","path of/geckodriver.exe");
DesiredCapabilities capabilities=DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(capabilities);
For more information You can go to this https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver link.
Please let me know if the issue doesn't get resolved.
You can handle the Firefox driver automatically using WebDriverManager.
This library downloads the proper binary (geckodriver) for your platform (Mac, Windows, Linux) and then exports the proper value of the required Java environment variable (webdriver.gecko.driver).
Take a look at a complete example as a JUnit test case:
public class FirefoxTest {
private WebDriver driver;
@BeforeClass
public static void setupClass() {
WebDriverManager.firefoxdriver().setup();
}
@Before
public void setupTest() {
driver = new FirefoxDriver();
}
@After
public void teardown() {
if (driver != null) {
driver.quit();
}
}
@Test
public void test() {
// Your test code here
}
}
If you are using Maven you have to put at your pom.xml
:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.1.0</version>
</dependency>
WebDriverManager does magic for you:
- It checks for the latest version of the WebDriver binary
- It downloads the WebDriver binary if it's not present on your system
- It exports the required WebDriver Java environment variables needed by Selenium
So far, WebDriverManager supports Chrome
, Opera
, Internet Explorer
, Microsoft Edge
, PhantomJS
, and Firefox
.