0

从相对初级的 Java 背景学习 Selenium。根据所有指南下载 JAR 并将它们导入 Eclipse,但它们与代码的功能没有任何关系。在网上到处搜索,但除非我发疯,否则找不到任何东西。附加的屏幕截图显示了引用的库以及代码:代码和罐子

代码本身是:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Firefox {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        
        System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        //comment the above 2 lines and uncomment below 2 lines to use Chrome
        //System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe");
        //WebDriver driver = new ChromeDriver();
        
        String baseUrl = "http://demo.guru99.com/test/newtours/";
        String expectedTitle = "Welcome: Mercury Tours";
        String actualTitle = "";

        // launch Fire fox and direct it to the Base URL
        driver.get(baseUrl);

        // get the actual value of the title
        actualTitle = driver.getTitle();

        /*
         * compare the actual title of the page with the expected one and print
         * the result as "Passed" or "Failed"
         */
        if (actualTitle.contentEquals(expectedTitle)){
            System.out.println("Test Passed!");
        } else {
            System.out.println("Test Failed");
        }
       
        //close Fire fox
        driver.close();

    }

}

4

1 回答 1

0

与Java无关,在我看来你下载了错误的库,应该Selenium Client不是Selenium Server

在此处输入图像描述

你可以在这里下载,然后选择你想要的版本。 https://www.selenium.dev/downloads/

于 2021-06-30T02:53:22.283 回答