The path to the driver executable must be set by the webdriver.gecko.driver system property;
Posted 软件测试杂谈
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了The path to the driver executable must be set by the webdriver.gecko.driver system property;相关的知识,希望对你有一定的参考价值。
今天安装了webdriver后,编写了一个测试小程序,但运行时控制台报了这样的错误:
1 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
解决过程:
1、查了一下,据说报这个错是因为在selenium3中,使用Firefox需要添加驱动。于是从晚上找驱动下载地址:
下载网址1:http://download.csdn.net/detail/just_h_mao/9670229
下载网址2: https://github.com/mozilla/geckodriver/releases/tag/v0.9.0
2、
注意:如果firefox安装时使用了非默认安装路径,则可以无法找到firefox.exe来启动执行此脚本的firefox浏览器。在new FirefoxDriver()前设置一下浏览器安装路径即可解决,如下:
1 package helloworld; 2 import org.openqa.selenium.*; 3 import org.openqa.selenium.By.ById; 4 import org.openqa.selenium.firefox.FirefoxDriver; 5 6 public class JavaTest { 7 8 public static void main(String[] args) { 9 // TODO Auto-generated method stub 10 11 WebDriver driver; 12 String baseurl; 13 System.setProperty("webdriver.gecko.driver", "F:\\WebDriver\\下载\\geckodriver-v0.11.1-win64\\geckodriver.exe");
14 driver=new FirefoxDriver(); 15 baseurl="http://www.sogou.com/"; 16 //打开搜狗首页 17 driver.get(baseurl+"/"); 18 //在搜索框输入XX 19 driver.findElement(By.id("query")).sendKeys("XX"); 20 //单击搜索按钮 21 driver.findElement(By.id("stb")).click(); 22 23 24 } 25 26 }
但运行后还是出现错误:
1495555671697 geckodriver INFO Listening on 127.0.0.1:30859 五月 24, 2017 12:07:52 上午 org.openqa.selenium.remote.ProtocolHandshake createSession 信息: Attempting bi-dialect session, assuming Postel‘s Law holds true on the remote end 1495555672392 mozprofile::profile INFO Using profile path C:\Users\admn\AppData\Local\Temp\rust_mozprofile.62d2gzZYduHH 1495555672416 geckodriver::marionette INFO Starting browser C:\Program Files (x86)\Mozilla Firefox\firefox.exe 1495555672563 geckodriver::marionette INFO Connecting to Marionette on localhost:18028 1495555677486 Marionette INFO Listening on port 18028 五月 24, 2017 12:07:57 上午 org.openqa.selenium.remote.ProtocolHandshake createSession 信息: Detected dialect: W3C Exception in thread "main" org.openqa.selenium.InvalidArgumentException: Expected [object Undefined] undefined to be a string Build info: version: ‘unknown‘, revision: ‘1969d75‘, time: ‘2016-10-18 09:43:45 -0700‘ System info: host: ‘admin‘, ip: ‘192.168.1.102‘, os.name: ‘Windows 8.1‘, os.arch: ‘amd64‘, os.version: ‘6.3‘, java.version: ‘1.8.0_31‘ Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{moz:profile=C:\Users\admn\AppData\Local\Temp\rust_mozprofile.62d2gzZYduHH, rotatable=false, timeouts={implicit=0, pageLoad=300000, script=30000}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=53.0.2, platformVersion=10.0, moz:processID=14196, browserName=firefox, platformName=windows_nt}] Session ID: 7a0a1695-fe51-4d87-a720-2f7c1baa7038 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:127) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:93) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:42) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601) at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274) at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:98) at helloworld.JavaTest.main(JavaTest.java:19)
以上是关于The path to the driver executable must be set by the webdriver.gecko.driver system property;的主要内容,如果未能解决你的问题,请参考以下文章
Selenium调用IE时报“The path to the driver executable must be set by the webdriver.ie.driver system prope
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received
registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web applicat
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received(
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received