Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firefox browser is not opening with selenium webbrowser code [duplicate]

Need guidance and help in the below one.

When the below code is executed, I am getting error. I am using the latest version of java, eclipse, firefox, and WebDrive jar file.

package firsttest1;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class helloselenium {
    public static void main(String[] args) {
        WebDriver driver;
        driver =new FirefoxDriver();
        String url ="http://www.google.com";
        driver.get(url);
    }
}

error....

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases at com.google.common.base.Preconditions.checkState(Preconditions.java:199) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109) at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:38) at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:91) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296) at org.openqa.selenium.firefox.FirefoxDriver.createCommandExecutor(FirefoxDriver.java:245) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:220) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:215) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:211) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:124) at firsttest1.helloselenium.main(helloselenium.java:12)

Version used: eclipse : neon version java : jdk1.8 fire fox: v48 WebDrive jar file : v 3.0.0 beta2

guide me in resolving this issue.

like image 755
SJR Avatar asked Aug 03 '16 18:08

SJR


3 Answers

You are using latest version of Selenium WebDriver i.e. Selenium 3.x, this version of webdriver doesn't support direct firefox launch. You have to set the SystemProperty for webdriver.gecko.driver.

Replace the Code:-

WebDriver driver;
driver =new FirefoxDriver();

With This code:-

WebDriver driver;
System.setProperty("webdriver.gecko.driver", "<Path to your WebDriver>");
driver =new FirefoxDriver();

You can get the information about latest changes here

You can download the latest Gecko driver from here

like image 75
Paras Avatar answered Oct 17 '22 06:10

Paras


Download the lastest version for geckoDriver here then set a System property called "webdriver.gecko.driver" and put on it the path to your geckoDriver executable path System.setProperty("webdriver.gecko.driver", "<path to your gecko driver executable>");

like image 32
BlackDeath Avatar answered Oct 17 '22 07:10

BlackDeath


Firefox driver is based on marionette starting with Selenium 3.0. Unlike, 2.x versions, it requires an external executable file. You should add it to your path. For more information, you should have a look at https://github.com/mozilla/geckodriver.

like image 2
Nicolas Henneaux Avatar answered Oct 17 '22 08:10

Nicolas Henneaux