我在Eclipse中运行包时看到错误

时间:2016-10-18 17:10:59

标签: java eclipse selenium

  

线程中的异常" main" java.lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver.gecko.driver系统属性设置;有关更多信息,请参阅https://github.com/mozilla/geckodriver。最新版本可以从https://github.com/mozilla/geckodriver/releases

下载

这是我的代码。

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);

    }

}

1 个答案:

答案 0 :(得分:0)

对于selenium 3.0及更高版本,必须指定gecko.driver路径。在初始化驱动程序之前,在代码中添加以下行,不会出现错误。

System.setProperty("webdriver.firefox.marionette","xxx\geckodriver.exe");
//xxx - path to geckodriver.exe file
WebDriver driver = new FirefoxDriver();