Selenium:浏览器正在打开但无法在浏览器中获取URL

时间:2017-10-20 18:20:13

标签: java selenium firefox

操作系统:Windows 10

执行环境:JavaSE-1.8(jre1.8.0_144)

构建路径上的JAR和类文件夹: 客户端联合3.6.0-sources.jar 客户combined3.6.0.jar 硒 - 服务器 - 独立-3.6.0.jar

浏览器: FireFox 56.0

代码段: System.setProperty(" webdriver.firefox.marionette"" C:/Users/admin/Downloads/geckodriver-v0.11.1-win32/geckodriver.exe"); WebDriver driver = new FirefoxDriver(); driver.get(" https://www.facebook.com&#34);

错误:

    Exception in thread "main" org.openqa.selenium.WebDriverException: Timed out waiting 45 seconds for Firefox to start.
Build info: version: '3.6.0', revision: '6fbf3ec767', time: '2017-09-27T16:15:26.402Z'
System info: host: 'ADMIN-PC', ip: '192.168.1.6', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_144'
Driver info: driver.version: FirefoxDriver
at org.openqa.selenium.firefox.XpiDriverService.waitUntilAvailable(XpiDriverService.java:112)
at org.openqa.selenium.firefox.XpiDriverService.start(XpiDriverService.java:97)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:79)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:217)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:140)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:120)
at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDriver.java:98)
at FacebookFriends.main(FacebookFriends.java:18)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:45149/hub/status] to be available after 45005 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:100)
at org.openqa.selenium.firefox.XpiDriverService.waitUntilAvailable(XpiDriverService.java:110)
... 8 more
Caused by: java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask.get(Unknown Source)
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:147)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:75)
... 9 more

4 个答案:

答案 0 :(得分:1)

我有此错误2天,对我来说,解决方案是在Set.Plataform中放置Platafor.ANY或Plataform.Windows,因为Plataform.WIN10不起作用,不需要木偶,并且我添加并且始终起作用,这仅适用。我希望这可以帮助其他人:

公共类主要{ 公共静态RemoteWebDriver驱动程序;

public static void main(String[] args) throws MalformedURLException {
    System.setProperty("webdriver.gecko.driver", "D:/Lib/geckodriver.exe");
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities().firefox();
    desiredCapabilities.setPlatform(Platform.ANY);
    desiredCapabilities.setBrowserName("firefox");

    driver = new RemoteWebDriver(new URL("http://172.20.19.182:5557/wd/hub"), desiredCapabilities);
    driver.navigate().to("http://www.google.com");
    driver.findElementByName("q").sendKeys("execute automation");
    driver.findElementByName("q").sendKeys(Keys.ENTER);
    driver.close();
    // write your code here
}

}

答案 1 :(得分:0)

您还可以尝试在geckodriver的路径中使用双\\

而不是使用:

System.setProperty(
    "webdriver.firefox.marionette",
    "C:/Users/admin/Downloads/geckodriver-v0.11.1-win32/geckodriver.exe");

您可以尝试使用

System.setProperty(
    "webdriver.gecko.driver",
    "C:\\Users\\admin\\Downloads\\geckodriver-v0.11.1-win32\\geckodriver.exe");

答案 2 :(得分:0)

首先,你正在使用一些旧版本的gecko驱动程序。来自:https://github.com/mozilla/geckodriver/releases

的最新版本

然后您需要使用以下命令设置系统属性:

File gecko = new File("C:/Users/admin/Downloads/geckodriver-v0.19.0-win32/geckodriver.exe");    
System.setProperty("webdriver.gecko.driver", gecko.getAbsolutePath());

如果您真的想在Difference between webdriver.firefox.marionette & webdriver.gecko.driver

上使用牵线木偶检查答案

答案 3 :(得分:0)

标题:问题已解决 接受的解决方案: - 使用最新版本的gecko驱动程序

使用的代码 - System.setProperty(" webdriver.gecko.driver"," C:\ Marionette \ geckodriver_1.exe");