Selenium - NoSuchWindowException in IE 11

I am trying to automate a webpage using selenium in IE11. I have set the protected mode settings to same level and zoom level is 100%. While running the test it opens the website however gives the exception just after. Below is the code used.

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

And the exception 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 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)

Any suggestions on how to resolve this.

Answers


First of all, don't use

capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);

as you have already set Protected mode settings. For the issue you are seeing, it should be because of the missing registry settings that is added as a prerequisite for running tests in IE11:

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


I am using IE 11 - 64 bit windows machine. This point worked for me.

For IE 11 only, you will need to set a registry entry on the target computer so that the driver can maintain a connection to the instance of Internet Explorer it creates.

For 32-bit Windows installations, the key you must examine in the registry editor is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE.

For 64-bit Windows installations, the key is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE.

Please note that the FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present.

Important: Inside this key, create a DWORD value named iexplore.exe with the value of 0.


The solution suggested by @David Kemp is not working for the ie 11 of windows 10 - 64 bit . I have added the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet explorer\Main\FeatureControl\FEATURE_BFCACHE according to the steps mentioned For IE 11 only following https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration but after opening the https certificate page (url https://my-page:9443) it is unable to execute driver.navigate().to("javascript:document.getElementById('overridelink').click()"); throwing NoSuchWindowException

However same works fine for ie 11 of windows 7-64 bit and able to execute the scripts .

The work around to make ie 11 work for win 10 is by setting initialBrowserUrl capabilities to https://my-page:9443 like below

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

but I am still confused why for ie11 / windows 10 it's different ?


I found that, if the launched browser is kept on focus, you will get that exception. As soon as you launch the webdriver, open any other window, for example, you can open eclipse as soon as the script launches IE Driver. Script execution starts, and then you can open you IE Driver.. to handle it through scripts, you add the below code:

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

Below solution also works if from current page you navigate on next page on some action/event and selenium driver doesnt recognise window :-

For 64-bit Windows installations, the key is:

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

Inside this create a DWORD value named iexplore.exe with the value of 0.


Added domain of AUT to list of "Trusted Sites" for i.e. in "Internet Options". Solved the problem.


IE Options --> Security Tab -> Uncheck "Enable Protected Mode" worked for me.


Add http://localhost/ to your trusted sites in IE11. This worked for me,after trying everything else without results.


Need Your Help

SaltStack : is it possible to apply states on the master and if so, how?

salt-stack

I am a total beginner with SaltStack but I have managed to setup some states on a machine and run them on a minion.

Calling startActivity() from outside of an Activity context

android android-activity android-context

I have implemented a ListView in my Android application. I bind to this ListView using a custom subclass of the ArrayAdapter class. Inside the overridden ArrayAdapter.getView(...) method, I assig...