【发布时间】:2020-03-14 00:28:43
【问题描述】:
我无法通过带有 Selenium 2.0 的 TestNG 启动浏览器。
请查看以下代码并需要您的帮助。
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Annotations {
@Test
public void openBrowser(){
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
}
}
【问题讨论】:
-
我们可以在调用 WebDriver driver = new FirefoxDriver(); 之前添加 System.setProperty("webdriver.gecko.driver", "location of your geckodriver.exe");
-
谢谢。因为我使用的是 selenium 2.0,所以不需要 geckodriver。虽然我已经尝试添加上面的行,但我得到了不同的错误。错误:失败:openBrowser org.openqa.selenium.WebDriverException:java.net.ConnectException:无法连接到 localhost/0:0:0:0:0:0:0:1:22105 构建信息:版本:'3.141。 59',修订:'e82be7d358',时间:'2018-11-14T08:25:53' 系统信息:主机:'VENKATESH-PC',ip:'192.168.43.51',os.name:'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_20' 驱动信息: driver.version: FirefoxDriver
-
尝试将 geckodriver.exe 放入系统环境变量中的 windows 路径变量中。或者,您可以通过降级 geckodriver.exe 来检查。