[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》 | 王小鸭自动发工资条VBA版
登录系统:用户名: 密码: 如果要讨论问题,请先注册。

[备忘]selenium的FirefoxDriver的安装

上一篇:[备忘]jquery的multiSelect控件,空白的问题
下一篇:[备忘]用纯js触发onTouchEnd方法

添加日期:2020/4/26 20:33:32 快速返回   返回列表 阅读1105次
(1)https://www.firefox.com.cn/
下载安装火狐

(2)下载gecko驱动
https://github.com/mozilla/geckodriver/releases
就是个exe文件,放到某个路径下

(3)工程里selenium版本要新一些,否则可能报错
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.0.0-alpha-5</version>
    <exclusions>
        <exclusion>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-server</artifactId>
    <version>4.0.0-alpha-2</version>
</dependency>    

(4)然后
System.setProperty("webdriver.firefox.bin", "C:\\Program Files\\Mozilla Firefox\\firefox.exe");
System.setProperty("webdriver.gecko.driver","D:\\chromedriver\\geckodriver.exe");     
WebDriver driver = new org.openqa.selenium.firefox.FirefoxDriver();
就行了。

(5)可能遇到的问题:
启动时报错:org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000ms
这个是fireFoxDriver去连接gecko,没连上。
可能是火狐浏览器太新,而Selenium版本太旧。
但我本机win7没问题,同样东西服务器windows2012上就报错。
搜了半天,发现gecko的v0.25.0版本开始,需要安装
 Microsoft Visual Studio redistributable runtime才行,否则gecko运行不起来,自然报错。
https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads
https://aka.ms/vs/16/release/vc_redist.x64.exe
装上就OK了。
(6)这个,或许有用吧
FirefoxOptions options = new FirefoxOptions();
options.setLegacy(false);
            
driver = new org.openqa.selenium.firefox.FirefoxDriver(options);

(7)FirefoxDriver貌似不支持mobile仿真,呵呵。
要是有需要touch,下拉的的就完蛋了

----------------------------------------------------
IE是这样写:
System.setProperty("webdriver.ie.driver", "D:\\chromedriver\\IEDriverServer.exe");
driver = new org.openqa.selenium.ie.InternetExplorerDriver();

驱动说是在这里下载:
https://www.nuget.org/packages/Selenium.WebDriver.IEDriver/
但我没找到。

Download version 3.150.1 for:
32 bit Windows IE (recommended) 
https://selenium-release.storage.googleapis.com/3.150/IEDriverServer_Win32_3.150.1.zip
64 bit Windows IE 
https://selenium-release.storage.googleapis.com/3.150/IEDriverServer_x64_3.150.1.zip
 

评论 COMMENTS
没有评论 No Comments.

添加评论 Add new comment.
昵称 Name:
评论内容 Comment:
验证码(不区分大小写)
Validation Code:
(not case sensitive)
看不清?点这里换一张!(Change it here!)
 
评论由管理员查看后才能显示。the comment will be showed after it is checked by admin.
CopyRight © 心缘地方 2005-2999. All Rights Reserved