2014-07-14 35 views
19

我想在IE11中使用硒自動化一個網頁。我已將保護模式設置設爲相同級別,縮放級別爲100%。在運行測試時,它會打開網站,但會在之後發出異常。以下是使用的代碼。Selenium - NoSuchWindowException在IE 11中

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"); 

和異常堆棧跟蹤

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 caused  connection 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 on closed 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', 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) 

就如何解決這個任何建議。

回答

22

首先,不使用

capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true); 

因爲你已經設置保護模式設置。對於這個問題,你所看到的,應該是因爲被添加作爲先決條件在IE11上運行測試丟失的註冊表設置:

https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration

+4

謝謝。對於任何面臨相同問題的人員(此處)(http://pcsupport.about.com/od/registry/ht/open-registry-editor.htm)是用於打開註冊表設置的參考鏈接 – Wanderer

+3

此配置的鏈接現在https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration –

10

我使用IE 11 - 64位Windows機器。這一點爲我工作。

僅適用於IE 11,您需要在目標計算機上設置註冊表項,以便驅動程序可以維護與其創建的Internet Explorer實例的連接。

對於32位Windows安裝,您必須在 註冊表編輯器,考查的重點是HKEY_LOCAL_MACHINE \ SOFTWARE \微軟\的Internet Explorer的 \ MAIN \ FeatureControl \ FEATURE_BFCACHE。

對於64位Windows安裝中,關鍵是 HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \微軟\的Internet Explorer的 \ MAIN \ FeatureControl \ FEATURE_BFCACHE。

請注意,FEATURE_BFCACHE子項可能會或可能不存在,如果不存在應創建。

重要:這裏面的關鍵,創建0

+0

哇,工作。但是輸入速度很慢 - 每分鐘一封信 - /任何想法? – Isengo

+1

希望您使用的是64位機器和64位IE驅動程序。改爲使用32位IE驅動程序。 –

+0

是的,這是訣竅!早先在SOF上發現它 – Isengo

1

的價值,我發現,如果啓動的瀏覽器保持專注,你會得到異常命名iexplore.exe一個DWORD值。只要啓動webdriver,打開任何其他窗口,例如,只要腳本啓動IE驅動程序,就可以打開eclipse。腳本開始執行,然後你可以打開你的IE驅動..通過腳本來處理它,您可以添加下面的代碼:如果從當前頁面你下次瀏覽頁面上的一些動作

public WebDriver driver, driver1; 
    System.setProperty("webdriver.ie.driver", System.getProperty(
        "webdriver.ie.driver", "./BrowserDrivers/IEDriverServer.exe")); 
      driver = new InternetExplorerDriver(cap); 
      this.driver.manage().deleteAllCookies(); 
      this.driver.manage().timeouts().implicitlyWait(WaitTimeConstants.WAIT_TIME_LONG, TimeUnit.SECONDS); 

      this.driver.get("yourApplication.com"); 
      this.driver.manage().window().maximize(); 

public WebDriver driver, driver1; 
System.setProperty("webdriver.ie.driver", System.getProperty(
       "webdriver.ie.driver", "./BrowserDrivers/IEDriverServer.exe")); 
     driver1 = new InternetExplorerDriver(cap); 
     this.driver1.manage().deleteAllCookies(); 

     this.driver1.get("http://www.google.com"); 
     this.driver1.manage().window().maximize(); 
0

下面的解決方案也適用/事件和硒司機犯規識別窗口: -

對於64位Windows安裝中,關鍵是:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet explorer\Main\FeatureControl\FEATURE_BFCACHE 

這裏面創建的0值名爲iexplore.exe的DWORD值。

5

@David Kemp建議的解決方案是不適用於窗口10的ie 11 - 64位。我照着只有以下https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration但打開HTTPS證書頁面(網址https://my-page:9443)後無法執行driver.navigate().to("javascript:document.getElementById('overridelink').click()");NoSuchWindowException

但是同樣工作正常,即11的提到IE 11中的步驟添加註冊表項HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet explorer\Main\FeatureControl\FEATURE_BFCACHE windows 7-64位並且能夠執行腳本。

周圍的工作,使即11工作勝利10是通過設置initialBrowserUrl能力https://my-page:9443像下面

capabilities.setCapability("initialBrowserUrl", "https://my-page:9443"); 

但我仍然感到困惑爲什麼IE11 /窗口10是不同的?

-1

http://localhost/添加到您在IE11中的可信站點。這對我來說,嘗試了一切後沒有結果。

1

將AUT的域添加到「可信站點」列表中,即在「Internet選項」中。解決了這個問題。

-1

IE選項 - >安全選項卡 - >取消選中「啓用保護模式」爲我工作。