新手搭建selenium总是有各种各样的错误,之前本人已搭建过一次,再次搭建还是出现了懵了圈的错误,捉急![尴尬]()

此篇博客记录错误,也帮助有需要的人快速搭建自动化环境,快速进入学习阶段。
selenium+firefox+java环境搭建就略过了,直接看问题吧。
错误1:org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms
在网上查阅了说是兼容问题
然后就开始找selenium版本与对应firefox版本匹配的记录
【Selenium】 -> 【FireFox】
2.25.0 -> 18
2.30.0 -> 19
2.31.0 -> 20
2.42.2 -> 29
2.44.0 -> 33 (不支持31,2014/12/1)
升级selenium jar包,或者是升级firefox。
更高的版本我也不知道,学习的时候就先凑着用吧,我自己是用2.45 -> 35.01;(firefox35.01可以用破解版httpwatch,抓包
)
错误2.org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed.
这个错误需要看一下你的firefox默认安装路径了;或者添加以下方法:
@Before
public void setUp() throws Exception {
System.setProperty("webdriver.firefox.bin", "D:\\Program Files\\Mozilla Firefox\\firefox.exe"); // firefox路径
driver = new FirefoxDriver();
baseUrl = "https://www.baidu.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
public void setUp() throws Exception {
System.setProperty("webdriver.firefox.bin", "D:\\Program Files\\Mozilla Firefox\\firefox.exe"); // firefox路径
driver = new FirefoxDriver();
baseUrl = "https://www.baidu.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
就是下面这句代码:
在new FirefoxDriver()之前加上。
System.setProperty("webdriver.firefox.bin", "D:\\Program Files\\Mozilla Firefox\\firefox.exe"); // firefox安装路径,别忘了双反斜杠;
最后来一张运行后的用例运行结果截图:
浙公网安备 33010602011771号