selenium - 线程中的异常未解决的编译问题:
问题描述
这是我的脚本:
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)
解决方案
您必须设置 Geckodriver(用于使用 Selenium 进行 Firefox 测试的可执行文件)的路径。
在谷歌中搜索
Geckodriver
。根据您的系统下载可执行文件(Win/Mac/Linux)
在测试中设置可执行文件的路径,如下所示 -
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(); }
}
推荐阅读
- javascript - 如何在浏览器的左上角添加水印文字
- java - 更新半连续变量的下限不再保持半连续
- windows-update - 如何从 Web API 使用 WSUS 远程 API 连接到 WSUS 服务器?
- php - 如何分别为不同的商店设置 Magento 商店时区
- python - 查找两个列表之间的相似性。通过根据列表中值的位置给出单独的权重
- php - Laravel 中间件:标头可能不包含多个标头,检测到新行
- javascript - 单击后不显示警报
- perl - 无法在 perl 脚本中获取 row_range
- javascript - 如何使用扩展运算符向对象添加属性,而不是覆盖它?
- java - ManagedBean 方法调用后渲染视图 [null] 时出错