-2

My code:

package pak0310;

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

public class class0310 
{
    public static void main(String[] args) 
    {
        // objects and variables instantiation
        WebDriver driver = new FirefoxDriver();
        String appUrl = "https://accounts.google.com";
        // launch the firefox browser and open the application url
        driver.get(appUrl);
        // maximize the browser window
        driver.manage().window().maximize();
        // declare and initialize the variable to store the expected title of the webpage.
        String expectedTitle = " Sign in - Google Accounts ";
        // fetch the title of the web page and save it into a string variable
        String actualTitle = driver.getTitle();
        // compare the expected title of the page with the actual title of the page and print the result
        if (expectedTitle.equals(actualTitle))
              {
                 System.out.println("Verification Successful - The correct title is displayed on the web page.");
              }
        else
              {
                 System.out.println("Verification Failed - An incorrect title is displayed on the web page.");
              }
        // enter a valid username in the email textbox
        WebElement username = driver.findElement(By.id("Email"));
        username.clear();
        username.sendKeys("TestSelenium");
        // enter a valid password in the password textbox
        WebElement password = driver.findElement(By.id("Passwd"));
        password.clear();
        password.sendKeys("password123");
        WebElement SignInButton = driver.findElement(By.id("signIn"));
        SignInButton.click();
        // close the web browser
        driver.close();
        System.out.println("Test script executed successfully.");
        // terminate the program
        System.exit(0);
       }
}

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:754)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
    at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:41)
    at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:115)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:329)
    at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:207)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:103)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:99)
    at pak0310.class0310.main(class0310.java:22)
...
halfer
  • 19,824
  • 17
  • 99
  • 186
  • See this QA [**`Why Firefox requires GeckoDriver?`**](https://stackoverflow.com/questions/43660195/why-firefox-requires-geckodriver/43661697#43661697) – undetected Selenium Oct 03 '17 at 12:24
  • 2
    Possible duplicate of [Selenium using Java - The path to the driver executable must be set by the webdriver.gecko.driver system property](https://stackoverflow.com/questions/38676719/selenium-using-java-the-path-to-the-driver-executable-must-be-set-by-the-webdr) – JeffC Oct 03 '17 at 13:58

3 Answers3

0

This error suggesting to use of geckodriver (post Selenium 3), to launch Firefox. You can refer

How to use the gecko executable with Selenium

halfer
  • 19,824
  • 17
  • 99
  • 186
0

In this similar question (https://stackoverflow.com/a/38752315/8195985) user Paras answered:

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; =new FirefoxDriver();

With This code:-

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

Maybe use that will help you.

Pv-Viana
  • 632
  • 7
  • 25
0
  1. Download geckodriver from https://github.com/mozilla/geckodriver/releases
  2. unzip folder you will get like this geckodriver.exe
  3. Copy that paste in some where and copy the complete path with driver.
  4. use below code in <path> place paste your path
System.setProperty("webdriver.gecko.driver", "your path");

WebDriver driver = new FirefoxDriver();
halfer
  • 19,824
  • 17
  • 99
  • 186
Sridhar
  • 1
  • 1
  • Please make an effort to format your posts appropriately. In particular, angle tags such as `` are **invisible** unless you backtick them. Use the preview feature! – halfer Oct 03 '17 at 14:30