我无法使用selenium webdriver(3.11)启动Firefox浏览器(53) 该代码适用于Chromedriver但在Firefox中有例外。
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class CNN {
public static void main(String[] args) {
WebDriver driver = new ChromeDriver();
driver.get("http://www.cnn.com");
String text =driver.findElement(By.xpath("//*[@id='intl_homepage1-zone-1']/div[2]/div/div[1]/ul/li[1]/article/a/h2")).getText();
System.out.println(text);
}
}
这是我得到的例外: -
Exception in thread "main" org.openqa.selenium.WebDriverException: java.net.ConnectException: Failed to connect to localhost/0:0:0:0:0:0:0:1:5542
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:08.638Z'
答案 0 :(得分:1)
您是否为Firefox下载并安装gecko驱动程序? 如果没有,请在Firefox中运行测试时使用它作为系统属性。