簡體   English   中英

在Eclipse中運行軟件包時看到錯誤

[英]I see an error while running a package in Eclipse

線程“主”中的異常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);

    }

}

對於硒3.0及更高版本,必須指定gecko.driver路徑。 在初始化驅動程序之前,將以下幾行添加到您的代碼中,並且不會出現錯誤。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM