首页 > 解决方案 > 线程中的异常未解决的编译问题:

问题描述

这是我的脚本:

package sampleTests;

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

public class AdminLogin {

public static void main(String[] args) {
    // TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver(); //Launches Firefox Browser with blank url
driver.close();
}

}

当我运行脚本时,出现以下错误,我尝试在类路径而不是模块路径中添加 java 库,但问题仍未解决,请有人帮忙;

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 sampleTests.AdminLogin.main(AdminLogin.java:10)

标签: selenium

解决方案


您必须设置 Geckodriver(用于使用 Selenium 进行 Firefox 测试的可执行文件)的路径。

  1. 在谷歌中搜索Geckodriver

  2. 根据您的系统下载可执行文件(Win/Mac/Linux)

  3. 在测试中设置可执行文件的路径,如下所示 -

    package sampleTests;
    
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    
    public class AdminLogin {
    
    public static void main(String[] args) {
        // TODO Auto-generated method stub
    System.setProperty("webdriver.gecko.driver",Path_of_Firefox_Driver");
    
    // example for Windows
     System.setProperty("webdriver.gecko.driver",D:\\GeckoDriver\\geckodriver.exe");
    
    WebDriver driver = new FirefoxDriver(); 
    driver.get("https://testautomationu.applitools.com/");
    driver.quit();
    }
    

    }


推荐阅读