UnreachableBrowserException尝试使用IEDriver在Selenium Webdriver中启动

时间:2013-06-12 13:10:14

标签: java internet-explorer selenium webdriver

我有一组在Firefox和Chrome中非常有效的自动化,我也想推出一个IEDriver实例。

我按照Selenium's Google Code wiki设置了IEDriver,并使用正确的路径(如果我改变路径,我会得到一个不同的异常,所以它绝对是正确的)。但由于某种原因,它仍然无法启动,只是超时。

启动它的代码(最后一行抛出异常):

        File ieDriver = new File("C:/Users/whatever/path/IEDriverServer.exe");
        System.setProperty("webdriver.ie.driver", ieDriver.getAbsolutePath());
        WebDriver ie = new InternetExplorerDriver();

例外是:

Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.33.0', revision: '4ecaf82108b2a6cc6f006aae81961236eba93358', time: '2013-05-22 12:00:17'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_21'
Driver info: driver.version: InternetExplorerDriver
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:201)
    at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:184)
    at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:174)
    at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:143)
    at uk.co.know.kiteTest.WebDriverManager.<init>(WebDriverManager.java:52)
    at uk.co.know.kiteTest.RunAutomations.main(RunAutomations.java:13)
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '2.33.0', revision: '4ecaf82108b2a6cc6f006aae81961236eba93358', time: '2013-05-22 12:00:17'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_21'
Driver info: driver.version: InternetExplorerDriver
    at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:165)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:62)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
    ... 7 more
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:38622/status] to be available after 20014 ms
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104)
    at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:163)
    ... 9 more
Caused by: com.google.common.util.concurrent.UncheckedTimeoutException: java.util.concurrent.TimeoutException
    at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:143)
    at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:79)
    ... 10 more

7 个答案:

答案 0 :(得分:2)

使用Chrome的Selenium WebDriver,问题:

(org.openqa.selenium.remote.UnreachableBrowserException) solution
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.35.0', revision: '8df0c6b', time: '2013-08-12 15:43:19'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_40'
Driver info: driver.version: ChromeDriver

如果您遇到问题,请转到chromedriver.exe位置并尝试执行exe。如果你能够执行exe,那么下面的代码将起作用。否则,它将是chromedriver文件夹的权限问题。更改文件夹位置或提供该文件夹的权限,然后双击chromedriver.exe。

<强>解决方案:

  System.setProperty("webdriver.chrome.driver", "C:/Driver/chromedriver.exe");
  System.out.println(System.getProperty("webdriver.chrome.driver"));

  WebDriver driver3 = new ChromeDriver();

答案 1 :(得分:2)

我遇到了同样的错误然后发现了这个问题。在我的情况下,事实证明我的系统上有64位版本的IEDriver.exe,但我使用的是32位Windows平台。所以这个错误表明操作系统无法执行驱动程序。我试图直接在命令提示符下运行驱动程序,以确定32位操作系统没有将64位驱动程序exe识别为可执行程序。

获取正确的32位IEDriver.exe解决了我的问题。

答案 2 :(得分:2)

转到主机(C:\ Windows \ system32 \ drivers \ etc) 并确保正确使用此行:      127.0.0.1 localhost

答案 3 :(得分:2)

尝试通过BrowserStack为移动设备执行Selenium脚本时遇到类似的异常。并经常发现这个异常被抛出。 最终意识到涉及虚拟机,仿真器花时间启动,从而导致 UnreachableBrowserException

通过设置重试次数(RetryCount)并进行多次尝试(retryAttempt)来检查Remote WebDriver的可用性,写下以下代码来处理此问题。

while(retryAttempt<=retryCount){
            try{

                WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
                return driver;
            }
            catch(UnreachableBrowserException e){
                Thread.sleep(10000);
                if(retryAttempt>retryCount){
                    logger.error("Remote Web Driver cannot be reached at this moment");
                }
            }
        }

答案 4 :(得分:1)

在我看来,你使用不正确的驱动程序初始化。 尝试我项目中的一段代码:

File file = new File("C:/Selenium/iexploredriver.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();

答案 5 :(得分:1)

我有同样的问题。这为我解决了这个问题:

DesiredCapabilities capabilitiesIE = DesiredCapabilities.internetExplorer();
capabilitiesIE.setCapability(
    InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver = new InternetExplorerDriver(capabilitiesIE);

答案 6 :(得分:0)

如果您收到此例外,只需下载新的Chrome驱动程序并在项目中提供。就是这样。为我工作:))