java – Selenium – NoSuchWindowException in IE 11
我試圖在IE11中使用selenium自動化網頁.我將保護模式設定設定為相同級別,縮放級別為100%.在執行測試時,它開啟網站,但是給出了異常.以下是使用的程式碼.
File file = new File("C:\\Users\\Desktop\\IEDriverServer.exe"); System.setProperty("webdriver.ie.driver", file.getAbsolutePath() ); DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); WebDriver driver = new InternetExplorerDriver(capabilities); driver.get("http://www.google.com");
並且異常stacktrace
Started InternetExplorerDriver server (32-bit) 2.39.0.0 Listening on port 38122 Jul 11, 2014 1:50:02 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute INFO: I/O exception (java.net.SocketException) caught when processing request: Software causedconnection abort: recv failed Jul 11, 2014 1:50:02 PM org.apache.http.impl.client.DefaultRequestDirector tryExecute INFO: Retrying request Exception in thread "main" org.openqa.selenium.NoSuchWindowException: Unable to find element onclosed window (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 18 milliseconds Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12' System info: host: 'Neeraj', ip: '10.136.180.161', os.name: 'Windows+7/">Windows 7',s.arch: 'amd64',os.version: '6.1', java.version: '1.7.0_60'Session ID: ab6edd65-8a66-41fa-be46-56fba7dbdfc9 Driver info: org.openqa.selenium.ie.InternetExplorerDriver Capabilities [{platform=WINDOWS, javascriptEnabled=true, elementScrollBehavior=0,ignoreZoomSetting=false,enablePersistentHover=true, ie.ensureCleanSession=false, browserName=internet explorer, enableElementCacheCleanup=true,unexpectedAlertBehaviour=dismiss, version=11, ie.usePerProcessProxy=false, cssSelectorsEnabled=true,ignoreProtectedModeSettings=true, requireWindowFocus=false,handlesAlerts=true, initialBrowserUrl=http://localhost:38122/, ie.forceCreateProcessApi=false, nativeEvents=true, browserAttachTimeout=0, ie.browserCommandLineSwitches=, takesScreenshot=true}] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:307) at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:348) at org.openqa.selenium.By$ById.findElement(By.java:220) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:299) at Test1.main(Test1.java:27)
關於如何解決這個問題的任何建議.
首先,不要使用
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
因為您已經設定了保護模式設定.對於您所看到的問題,應該是因為缺少的登錄檔設定被新增為在IE11中執行測試的先決條件:
SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration" rel="nofollow,noindex" target="_blank">https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration
程式碼日誌版權宣告:
翻譯自:http://stackoverflow.com/questions/24746777/selenium-nosuchwindowexception-in-ie-11