Rana Haram Rana Haram - 1 year ago 89
Java Question

selenium installation hurdle "importfirefoxdriver"

I'm trying to download selenium web driver using eclipse and I am on the final step and successfully imported web driver, however, when I attempt to do the same for firefox I don't get the import option. Any Suggestions? Is there anything wrong with the code below?


package webdriver_project;

import org.openqa.selenium.WebDriver;

public class webdriver_module_1 {
public static void main(String[] args) {
WebDriver driver = new firefoxDriver();


Answer Source

If you are using Firefox version 48 or later, you must first download Marionete Driver from here: https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver

Choose a version suitable for your system (windows/linux, 32 or 64bit), download it and update the Path system variable to add the full directory path to the executable.
See an official information in the changelog: https://github.com/SeleniumHQ/selenium/blob/master/dotnet/CHANGELOG

Geckodriver is now the default mechanism for automating Firefox. This is Mozilla's implementation of a driver for that browser, and is required for automating Firefox versions 48 and above.

I am not sure how do you download selenium using eclipse. Did you download libraries (jars) from their page and place it manually as externall jars in the Eclipse using Java Build Path / Libraries option ?

Anyway, in my opinion the easiest way is to convert the project into Maven project:

  • first install Maven plugin using Eclipse Marketplace option: http://www.eclipse.org/m2e/
  • next right click on the project in Eclipce, and then choose Configure/Convert to Maven project. Next edit pom.xml file and add to it a dependency from Selenium webpage: http://docs.seleniumhq.org/download/maven.jsp


The whole content of pom.xml in my example project:

<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">

Finally create the below java class, change a path pointing to Marionette driver (geckodriver.exe), right click on this class and run it as Java application. If everything is ok, it should lauch Firefox, go to google webpage, search a word "selenium" and display search results for 5 seconds:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Test {

    public static void main(String ... x){
        // Path to Marionette driver
        System.setProperty("webdriver.gecko.driver", "C:/serwery/geckodriver.exe");

        WebDriver driver = new FirefoxDriver();



        try {
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download