Wanderer
Wanderer

Reputation: 476

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.

Upvotes: 22

Views: 64026

Answers (10)

Samarth
Samarth

Reputation: 150

You can follow a few options from below:

  1. Use relative paths in the project, later you can choose to get its absolute path.
  2. Setting the Protected mode setting for all, to either enabled or disabled.
  3. Try understanding what really this exception mean "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"

This states that whatever being done by your code (the web driver) is not able to identify the window of IE.

The possible causes can be: a. Multiple driver instances are already running which were instantiated by older runs and could not have been terminated by quite(). b. The sometimes when you use close() on a driver it will not terminate the IE Driver, so use quite() after closing inside a finally block. Yes, add some Exception handling to avoid the above issue.

  1. Exception "org.openqa.selenium.NoSuchWindowException" also suggests that web driver instance is not able to get the handle of IE's window tab. I faced this issue when accidentally, the browser was closed and the code was still trying to locate and do some action on a web element. In this case, the driver throws this exception to tell that there is no IE browser opened at all.

  2. Having a check on the opening of browser can also help, I usually keep some piece of code that gives logs of used Driver object and the port where it is trying to connect and to which browser to.

For me, point 4 & 5 worked. but you might wanna just change the web driver's service i.e. browser. IE is just too slow sometimes to honour the selenium API calls :(

Upvotes: 0

Venkatesh Pothula
Venkatesh Pothula

Reputation: 358

Ignore above all... i have tried below line in my desired capabilities for IE driver then its worked .. :)

            ieCapabilities.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL,false);

Upvotes: 0

Ponns
Ponns

Reputation: 159

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

Upvotes: 1

Jeevan Adiga
Jeevan Adiga

Reputation: 448

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

Upvotes: 1

IchimGA
IchimGA

Reputation: 11

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

Upvotes: 0

Som
Som

Reputation: 4728

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 ?

Upvotes: 8

meenal
meenal

Reputation: 31

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.

Upvotes: 3

Pallavi
Pallavi

Reputation: 11

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

Upvotes: 1

Solomon Raja
Solomon Raja

Reputation: 1810

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.

Upvotes: 11

Sitam Jana
Sitam Jana

Reputation: 3129

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

Upvotes: 24

Related Questions