尝试即时启动InternetExplorerDriver时出现一个奇怪的错误。我编写了以下代码:
public static void main(String[] args) {
System.setProperty("webdriver.ie.driver", "C:\\Program Files\\Internet Explorer\\iexplore.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.google.com");
}
出现Internet Explorer,将其设置为
http://--port=26290
,如下所示:正如我编写的那样,它永远都不会到达Google。
大约十秒钟后,我在控制台中得到了这个堆栈跟踪:
(TestBase.main(TestBase.java:358)是我实例化驱动程序的行。)
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.40.0', revision: '4c5c0568b004f67810ee41c459549aa4b09c651e', time: '2014-02-19 11:13:01'
System info: host: 'LT10387', ip: '192.168.0.82', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_45'
Driver info: driver.version: InternetExplorerDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:567)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:218)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:203)
at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:193)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:183)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:154)
at com.gdit.fwa.informant.webui.base.selenium.TestBase.main(TestBase.java:358)
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '2.40.0', revision: '4c5c0568b004f67810ee41c459549aa4b09c651e', time: '2014-02-19 11:13:01'
System info: host: 'LT10387', ip: '192.168.0.82', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_45'
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:546)
... 6 more
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:26290/status] to be available after 20002 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104)
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:163)
... 8 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)
... 9 more
Caused by: java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask.get(FutureTask.java:201)
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130)
... 10 more
是什么原因造成的?
最佳答案
这里存在问题:
System.setProperty("webdriver.ie.driver", "C:\\Program Files\\Internet Explorer\\iexplore.exe");
此属性是IEDriver的位置,而不是IE本身的位置:
https://code.google.com/p/selenium/wiki/InternetExplorerDriver
下载IEDriver,将其放置在合理的位置,并将其放置在该属性中。