Selenium与Firefox版本不兼容

更新Firefox到54.0后发现以前的基于Selenium 2.48.2的测试程序报错:
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 m

百度后得知Selenium和Firefox间存在版本兼容问题。(其它浏览器相信也是一样的)

更新selenium到3.4.0后运行测试,依然报错:
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

到上述地址后发现,自Selenium 3后以Geckodriver作为Firefox的默认WebDriver。Geckodriver是一个以代理的形式,让Selenium程序和基于Gecko的浏览器,如Firefox交互的程序。
注:此版本(v0.17.0)的Geckodriver还没有实现所有功能,不能完美兼容Selenium,并且对Firefox v53或更新版本支持更好。

Selenium会从系统环境参数里寻找Geckodriver,你可以
1,在将其设置在path环境参数中
set PATH=%PATH%;%gecko_path%
2,在代码中添加系统变量
System.setProperty(“webdriver.gecko.driver”, “gecko_path”);
3,在启动java时添加参数
java -Dwebdriver.gecko.driver=%gecko_path% YourApplication
在bash环境中也可以用下面方式设置并找到geckodriver
% export PATH=$PATH:/home/user/bin
% whereis geckodriver
geckodriver: /home/user/bin/geckodriver

本人采取第一种方式,在系统环境变量path中添加Geckodriver的路径,旧测试程序正确运行。部分输出:
1498814251334 geckodriver INFO Listening on 127.0.0.1:15516
1498814252998 geckodriver::marionette INFO Starting browser C:\Program Files (x86)\Mozilla Firefox\firefox.exe with args ["-marionette"]
1498814283823 Marionette INFO Listening on port 52325

P.S. 从下面路径能查看Selenium支持的FireFox版本:
selenium-server-standalone-3.4.0.jar\org\openqa\selenium\firefox\webdriver.xpi\install.rdf

<!-- Firefox -->
<em:targetApplication>
	<Description>
		<em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
		<em:minVersion>3.0</em:minVersion>
		<em:maxVersion>48.0</em:maxVersion>
	</Description>
</em:targetApplication>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值