0

I was written this code to open Mozilla Firefox browser

package com.webdrivercommands;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class WDcommands_Test1 {
public static void main(String[] args) throws InterruptedException {
    // TODO Auto-generated method stub

    //Launch chrome Browser
    //setproperty(method)

    System.setProperty("Webdriver.gecko.driver", "C:\\Java Selenium\\geckodriver.exe");

    WebDriver driver=new FirefoxDriver();

    //WebDriver(class) 
    //driver (object)

    //wait Time
    Thread.sleep(5000);

    //close the browser close(method)
    driver.close();
}
}

After Run the program i got the below error..but already extract the geckodriver(Firefox driver) into my system

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:847) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:125) at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:43) at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:168) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:346) at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:168) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:125) at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:103) at com.webdrivercommands.WDcommands_Test1.main(WDcommands_Test1.java:17)

Dave2e
  • 22,192
  • 18
  • 42
  • 50

1 Answers1

0

example 1: launch FF in blank temp profile:

    @BeforeClass
    public static void setUpClass() {
        FirefoxOptions options = new FirefoxOptions();
        options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
        System.setProperty("webdriver.gecko.driver", "C:\\Users\\pburgr\\Desktop\\geckodriver-v0.19.1-win64\\geckodriver.exe");
        driver = new FirefoxDriver(options);
        driver.manage().window().maximize();}

example 2: launch FF in blank temp profile with some preferences

@BeforeClass
public static void setUpClass() {
    FirefoxOptions options = new FirefoxOptions();  
    FirefoxProfile selenium_profile = new FirefoxProfile();
    selenium_profile.setPreference("browser.download.folderList",2);
    selenium_profile.setPreference("browser.download.dir", "C:\\Users\\pburgr\\Desktop\\BP_usr_tmp\\");
    selenium_profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    options.setProfile(selenium_profile);
    options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
    System.setProperty("webdriver.gecko.driver", "C:\\Users\\pburgr\\Desktop\\geckodriver-v0.19.1-win64\\geckodriver.exe");
    driver = new FirefoxDriver(options);
    driver.manage().window().maximize();}

example 3: lauch FF with existing FF profile:

@BeforeClass
public static void setUpClass() {
    FirefoxOptions options = new FirefoxOptions();
    ProfilesIni allProfiles = new ProfilesIni();         
    FirefoxProfile selenium_profile = allProfiles.getProfile("selenium_profile");
    options.setProfile(selenium_profile);
    options.setBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
    System.setProperty("webdriver.gecko.driver", "C:\\Users\\pburgr\\Desktop\\geckodriver-v0.19.1-win64\\geckodriver.exe");
    driver = new FirefoxDriver(options);
    driver.manage().window().maximize();}
pburgr
  • 1,722
  • 1
  • 11
  • 26