问题: selenium + java 运行提示如下:
[selenium 3.5.3 + java 1.8.0]
"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"
参考:https://stackoverflow.com/questions/38676719/selenium-using-java-the-path-to-the-driver-executable-must-be-set-by-the-webdr
分别制定了geckodriver 和 firefox 的位置如下:
】[selenium 3.5.3 + java 1.8.0]
"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"
参考:https://stackoverflow.com/questions/38676719/selenium-using-java-the-path-to-the-driver-executable-must-be-set-by-the-webdr
The
Selenium
client bindings will try to locate the geckodriver
executable from the system PATH
. You will need to add the directory containing the executable to the system path.- On Unix systems you can do the following to append it to your system’s search path, if you’re using a bash-compatible shell:
export PATH=$PATH:/path/to/geckodriver
- On Windows you need to update the Path system variable to add the full directory path to the executable. The principle is the same as on Unix.
All below configuration for launching latest firefox using any programming language binding is applicable for
Selenium2
to enable Marionette explicitly. With Selenium 3.0 and later, you shouldn't need to do anything to use Marionette, as it's enabled by default.
To use Marionette in your tests you will need to update your desired capabilities to use it.
[popexizhi: 这里自己使用的是3.5.3应该不用下载才对,但看了不可以,不知道为什么,下载了一下,在下面代码中指定了一下就可以运行了,我本地最后用55.0firefox 才行, geckodriver-v0.19.0-win64 的 https://github.com/mozilla/geckodriver/releases
v0.19.0 支持如下:
- Firefox 55.0 (and greater)
- Selenium 3.5 (and greater)
]
Java :
As exception is clearly saying you need to download latest
geckodriver.exe
from here and set downloaded geckodriver.exe
path where it's exists in your computer as system property with with variable webdriver.gecko.driver
before initiating marionette driver and launching firefox as below :-//if you didn't update the Path system variable to add the full directory path to the executable as above mentioned then doing this directly through code
System.setProperty("webdriver.gecko.driver", "path/to/geckodriver.exe");
//Now you can Initialize marionette driver to launch firefox
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
WebDriver driver = new MarionetteDriver(capabilities);
【popexizhi:分别制定了geckodriver 和 firefox 的位置如下:
public class ExampleForFireFox { public static void main(String[] args){ System.setProperty("webdriver.gecko.driver", "G:\\w\\selenium\\geckodriver-v0.19.0-win64\\geckodriver.exe"); // System.setProperty("webdriver.firefox.bin", "D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe"); WebDriver driver = new FirefoxDriver(); driver.get("http://192.168.1.88"); System.out.println("title: " + driver.getTitle()); } }
没有评论:
发表评论