(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
|