Selenium - NoSuchWindowException in IE 11

纵饮孤独 提交于 2019-11-27 20:33:12
Sitam Jana

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

Solomon Raja

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!