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
This is my code.
package newpackage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class MyClass {
public static void main(String[] args) {
//declaration and instatiation of objects/variables
WebDriver driver = new FirefoxDriver();
String baseUrl = "http://newtours.demoaut.com";
String expectedTitle = "Welcome: Mercury Tours";
String actualTitle ="";
//launch firefox and direct it to the URL
driver.get(baseUrl);
//get the actual value of the title
actualTitle = driver.getTitle();
if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed");
}else {
System.out.println("Test failed");
}
//close firefox
driver.close();
//exit the program
System.exit(0);
}
}
For selenium 3.0 and above it is mandatory to specify gecko.driver path. Add below lines to your code before initializing driver and error will not appear.
System.setProperty("webdriver.firefox.marionette","xxx\geckodriver.exe");
//xxx - path to geckodriver.exe file
WebDriver driver = new FirefoxDriver();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.