selenium firefox 启动报错 Timed out

原创
2020/02/11 18:16
阅读数 2.6K

搭建seleinum测试环境,代码如下

WebDriver driver; // 声明WebDriver
		String dirver = "browser" + File.separator +  "geckodriver.exe";
		System.setProperty("webdriver.firefox.marionette",dirver);
		// 指定Firefox浏览器的路径
		String Url = "https://s.taobao.com/search?q=led&imgfile=&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&spm=a21bo.2017.201856-taobao-item.1&ie=utf8&initiative_id=tbindexz_20170306"; // 百度的地址
		driver = new FirefoxDriver(); // new一个FirefoxDriver()
		driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // 设置隐式等待10秒钟
		driver.get(Url); // 打开百度首页
		driver.manage().window().maximize(); // 把浏览器窗口最大化

		try {
			Thread.sleep(3000); // 让线程等待3秒钟
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		driver.quit(); // 退出driver
		

报错如下:


Exception in thread "main" org.openqa.selenium.WebDriverException: Timed out waiting 45 seconds for Firefox to start.
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-U0KG7GG', ip: '192.168.127.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
Driver info: driver.version: FirefoxDriver
	at org.openqa.selenium.firefox.XpiDriverService.waitUntilAvailable(XpiDriverService.java:247)
	at org.openqa.selenium.firefox.XpiDriverService.start(XpiDriverService.java:159)
	at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:563)
	at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
	at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
	at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:147)
	at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
	at dev.trade.browser.core.TestFirefox.main(TestFirefox.java:19)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:18027/hub/status] to be available after 45002 ms
	at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100)
	at org.openqa.selenium.firefox.XpiDriverService.waitUntilAvailable(XpiDriverService.java:245)
	... 8 more
Caused by: java.util.concurrent.TimeoutException
	at java.util.concurrent.FutureTask.get(FutureTask.java:205)
	at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:156)
	at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75)
	... 9 more

原因: 使用Marionette驱动程序,该驱动程序不再适用于FF版本53和Selenium 3.5或更高版本。应该把

System.setProperty("webdriver.firefox.marionette",dirver);

改成:

System.setProperty("webdriver.gecko.driver",dirver);

现在我的本地Firefox运行正常。

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部