2
votes

My FireFox Version 49.0.1 Selenium Version: Selenium-java-3.0.0-beta3 Java: 8.0.1010.13 I have replaced all the existing Selenium Jar Files with the new files. Added the gecko.Driver to my code still I am seeing this message:

Error Message: java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property;

My Code:

import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class AbstractPage {
WebDriver Driver =new FirefoxDriver();

@Before
public void Homescreen() throws InterruptedException
{
    System.getProperty("Webdriver.gecko.driver", "C:/geckodriver.exe");
    System.setProperty("Webdriver.firefox.bin", "C:/Program Files (x86)/Mozilla Firefox/firefox.exe");      
    Driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    Driver.get("URL");
    Driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}

@After
public void TestComplete()  {
    Driver.close();
}

@Test
public void Projects()  {
    Driver.findElement(By.id("login-form-username")).sendKeys("Login");
    Driver.findElement(By.id("login-form-password")).sendKeys("Password");
    Driver.findElement(By.id("quickSearchInput")).sendKeys("ID");

        }

}

3
Unzip the Gecko driver and give the complete path to the system.property - Chandra Shekhar

3 Answers

0
votes

You can remove main() method from the code. unzip your gecko driver and save it to your local system with wires.exe.

my sample class path is

G:\ravik\Ravi-Training\Selenium\Marionette for firefox\wires.exe

public class AbstractPage 
{
WebDriver Driver;
System.setProperty("WebDriver.gecko.Driver", "C:\\TEMP\\Temp1_geckodriver-v0.10.0-win64.zip");
 Driver=new FirefoxDriver();
@Before
public void Homescreen() throws InterruptedException
{

    Driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    Driver.get("https://QualityAssurance.com");
    Driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    Driver.findElement(By.id("login-form-username")).sendKeys("Login");
    Driver.findElement(By.id("login-form-password")).sendKeys("Password");
    //JavascriptExecutor js = (JavascriptExecutor) Driver;
    //js.executeScript("document.getElementById('login-form-password').setAttribute('value', val );");
}

@After
public void TestComplete()  {
    Driver.close();
}

@Test
public void Projects()  {
    Driver.findElement(By.id("quickSearchInput")).sendKeys("WMSSE-229");
0
votes

Please replace below line

System.setProperty("WebDriver.gecko.Driver", C:\\TEMP\\Temp1_geckodriver-v0.10.0-win64.zip");

You should pass geckodriver.exe not Zip file.

String driverPath = "F:/Sample/Selenium3Example/Resources/";
System.setProperty("webdriver.firefox.marionette", driverPath+"geckodriver.exe");

You can make your code more cleaner when posting here.

0
votes

You must do something like this:

System.setProperty("webdriver.gecko.driver", "C:/geckodriver.exe");
System.setProperty("webdriver.firefox.bin", "C:/Program Files (x86)/Mozilla Firefox/firefox.exe");

This is a working example, it make you know the context what the above code snippet used

package selenium;

import static org.junit.Assert.fail;

import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Junit4FirefoxJava {

    private WebDriver driver;
    private String baseUrl;
    private boolean acceptNextAlert = true;
    private StringBuffer verificationErrors = new StringBuffer();

    @Before
    public void setUp() throws Exception {
        System.setProperty("webdriver.gecko.driver", "C:/geckodriver.exe");
        System.setProperty("webdriver.firefox.bin", "C:/Program Files (x86)/Mozilla Firefox/firefox.exe");
        driver = new FirefoxDriver();
        baseUrl = "http://www.bing.com/";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @Test
    public void testJunit4IeJava() throws Exception {
        driver.get(baseUrl + "/");
        driver.findElement(By.id("sb_form_q")).click();
        driver.findElement(By.id("sb_form_q")).clear();
        driver.findElement(By.id("sb_form_q")).sendKeys("NTT data");
        driver.findElement(By.id("sb_form_go")).click();
        driver.findElement(By.linkText("NTT DATA - Official Site")).click();
        driver.findElement(By.id("js-arealanguage-trigger")).click();
        driver.findElement(By.linkText("Vietnam - English")).click();
        driver.findElement(By.id("MF_form_phrase")).clear();
        driver.findElement(By.id("MF_form_phrase")).sendKeys("internet");
        driver.findElement(By.cssSelector("input.search-button")).click();
    }

    @After
    public void tearDown() throws Exception {
        driver.quit();
        String verificationErrorString = verificationErrors.toString();
        if (!"".equals(verificationErrorString)) {
            fail(verificationErrorString);
        }
    }

    private boolean isElementPresent(By by) {
        try {
            driver.findElement(by);
            return true;
        } catch (NoSuchElementException e) {
            return false;
        }
    }

    private boolean isAlertPresent() {
        try {
            driver.switchTo().alert();
            return true;
        } catch (NoAlertPresentException e) {
            return false;
        }
    }

    private String closeAlertAndGetItsText() {
        try {
            Alert alert = driver.switchTo().alert();
            String alertText = alert.getText();
            if (acceptNextAlert) {
                alert.accept();
            } else {
                alert.dismiss();
            }
            return alertText;
        } finally {
            acceptNextAlert = true;
        }
    }

}