繁体   English   中英

在Eclipse IDE中执行Selenium脚本时出错

[英]Error while executing Selenium script in Eclipse IDE

我收到以下脚本的以下错误。 我已将所有jar文件添加到库中。

============================================================
Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    WebDriver cannot be resolved to a type
    FirefoxDriver cannot be resolved to a type

    at webdriver/Demo.Sample.main(Sample.java:11)
=============================================================
package Demo;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Sample {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("hello");
        WebDriver driver = new FirefoxDriver();
        driver.get("http://www.google.com");
    }
}

好像您导入了错误的jar文件。 https://selenium-release.storage.googleapis.com/index.html?path=2.53/下载selenium-server-standalone-2.53.1.jar文件,并将其导入eclipse中并删除其他jar文件。

由于您尝试使用Selenium WebDriver自动化Firefox,因此还需要下载Firefox可执行二进制文件。 根据您的浏览器版本,您可以从https://github.com/mozilla/geckodriver/获取gecko驱动程序

在驱动程序初始化之前,在代码中添加以下行,并提供具有名称和范围的Firefox可执行二进制文件的绝对路径:

System.setProperty("webdriver.firefox.driver", "pathToGeckoBinaryExecutable");

下面是修改后的代码:

package Demo;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Sample {

    public static void main(String[] args) {
        System.setProperty("webdriver.firefox.driver", "pathToGeckoBinaryExecutable\\geckodriver.exe"); // Provide your system path to the gecko driver with name and extension here
        System.out.println("hello");
        WebDriver driver = new FirefoxDriver();
        driver.get("http://www.google.com");
    }
}

希望对您有帮助...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM