我使用 Ubuntu Studio 16.10,并设置了 Selenium 3.0.1。然后我安装了 geckodriver,并使用了以下内容
WebDriver driver = new FirefoxDriver();
System.setProperty("webdriver.gecko.driver", "/home/myacc/eclipse/jee-neon2/eclipse/geckodriver");
driver.get("www.google.co.in");
但我仍然收到以下错误:
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases
at com.google.common.base.Preconditions.checkState(Preconditions.java:199)
答案1
设置系统属性后初始化驱动程序实例。
System.setProperty("webdriver.gecko.driver", "/home/myacc/eclipse/jee-
neon2/eclipse/geckodriver");
答案2
您必须下载更新的 geckodriver。您不能同时安装旧的 geckodriver 和更新的 Firefox。
去: https://github.com/mozilla/geckodriver/releases
下载并解压selenium脚本文件夹中的“geckodriver-v0.32.0-linux64.tar.gz”文件并运行。
现在将此目录放入您的 PATH 变量中:
export PATH=$PATH:/home/aitor/mygekodriverdirectory
或者你可以保存在 /usr/bin 中,但这样很危险,因为你必须频繁更新它……对我来说,更改 PATH 更容易
最后运行脚本:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("www.google.co.in");