【问题标题】:I see an error while running a package in Eclipse在 Eclipse 中运行包时出现错误
【发布时间】:2017-02-28 01:56:36
【问题描述】:

线程“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);

    }

}

【问题讨论】:

  • 当你按照它的指示...?
  • 在问题中添加适当的标签很重要。大多数寻找可以回答的问题的人都会搜索他们熟悉的语言,因此您至少应该将其作为标签包含在内。您还应该阅读 Stack Overflow 的 markdown 格式,以使您的问题更具可读性。这次我为你编辑了你的问题;请学会自己做。

标签: java eclipse selenium


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-08
    • 1970-01-01
    • 2021-04-10
    • 2014-04-30
    • 2016-11-02
    • 2018-05-30
    • 1970-01-01
    • 2012-02-01
    相关资源
    最近更新 更多