当我学习selenium时,我正在尝试使用selenium从eclipse启动firefox浏览器。
我的导师写了下面的代码,但是当我尝试相同的代码时,我得到了这个异常 -
Exception in thread "main" java.lang.IllegalStateException:
驱动程序可执行文件的路径必须由 webdriver.gecko.driver 系统属性设置;欲了解更多信息,请参阅
Link1 。最新版本可以从
下载代码:
package appselenium1;
import org.openqa.selenium.firefox.FirefoxDriver;
public class A {
public static void main(String[] args) {
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://www.gmail.com");
}
}
最佳答案
您面临此异常,因为您没有使用 gecko 驱动程序,这是在 selenium 中启动和发送命令所必需的。
您可以从 here 下载最新版本的 gecko 版本
试试这个:
package appselenium1;
import org.openqa.selenium.firefox.FirefoxDriver;
public class A {
static WebDriver driver ;
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Downloads\\geckodriver-v0.20.1-win64\\geckodriver.exe");
driver = new FirefoxDriver();
driver.get("http://www.gmail.com");
}
}
关于java - 尝试在 Eclipse 中使用 selenium jar 文件启动 Firefox 浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51422393/