您的位置:首页 > 其它

【问题】selenium-server-standalone和webdriver版本不对应的问题

2016-10-17 19:01 525 查看
在学习selenium的过程中难免会遇到各种各样的问题,俗话说的好,好记性不如烂笔头,所以将遇到的问题整理到博客中,其一是为了方便自己回顾,其二是为了帮助遇到同样问题的小伙伴们,由于不是很了解selenium的内部结构,所以都是凭借自己的理解写的,如果有理解上的偏差,希望小伙伴们不吝赐教。

原来的认识:firefox不需要单独下载driver,集成在了selenium客户端中

服务器环境配置

selenium-server-standalone 3.0.0.jar

firefox 46.0

客户端编写代码

WebDriver driver= new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub/"), DesiredCapabilities.firefox());
driver.get("http://www.baidu.com");
Thread.sleep(3000);
driver.quit();


运行代码

在保证服务器端服务开启的情况下,运行客户端代码=》运行结果如下

Exception in thread "main" org.openqa.selenium.WebDriverException:
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


解决

参考了乙醇的博客(selenium3.0的发布):http://www.cnblogs.com/nbkhic/p/5779453.html

分析原因:

由于服务器上的server版本是3.0.0的,所以会不会和selenium3.0有关系?如果有关系,那就是版本对应问题了,根据乙醇的博客得知,selenium3.0之后,需要通过Mozilla官方的geckodriver来支持firefox,因为最新版本的firefox已经换引擎了,老版本的firefox driver不支持新引擎。所以这里尝试两种解决办法:将server的版本降低或者将driver的版本提高

(1)将driver的版本提高

根据提示在“https://github.com/mozilla/geckodriver/releases”下载了geckodriver.exe,将该driver放置到服务器端的“C:\Windows\System32”文件夹下,然后再次在客户端运行上面的代码==》运行成功

(2)将server的版本降低

将原来的selenium-server-standalone 3.0.0.jar版本降低为selenium-server-standalone 2.42.8.jar,然后通过“java -jar path\selenium-server-standalone 2.42.8.jar”命令启动server,在客户端运行上面的代码==》运行成功
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  firefox webdriver server
相关文章推荐