运行环境
浏览器版本:firefox50.1.0
selenium:selenium2.53.1
运行脚本
package simpletest;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class ById {
public static void main(String[] args) {
WebDriver driver = null;
System.setProperty("webdriver.gecko.driver", "/Users/chenxuejiao/TestTools/selenium2.53.1/geckodriver");
driver = new FirefoxDriver();
driver.get("https://www.baidu.com/");
driver.close();
}
}
运行时出现的问题
使用selenium运行访问百度首页时失败,提示org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms
原因分析
网上搜索,造成此问题原因是由于firefox版本和selenium版本不匹配造成的。由于我的firefox版本比较新,所以我猜想,应该是我的selenium jar包过低。
解决方案
下载最新的selenium-server-standalone-3.0.1后,程序正常运行。