5

While using IE for automation using Selenium Webdriver, I am able to open the URL but finding the element on that page is throwing the following exception:

org.openqa.selenium.NoSuchWindowException: Unable to find element on closed window (WARNING: The server did not provide any stacktrace information)

I have tried the driver.switchTo.window() method but it's not working. I have searched it for hours and I am not getting anywhere.

Here's the code:

public static Selenium selenium;

public static void main(String args[]) {

    try {

        System.setProperty(
            "webdriver.ie.driver",
            "D:\\Driver\\IEDriverServer_Win32_2.32.3_latest\\IEDriverServer.exe");

        DesiredCapabilities capab = DesiredCapabilities.internetExplorer();
        capab.setCapability(
            InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
            true);

        WebDriver driver = new InternetExplorerDriver(capab);
        driver.get("http://www.google.com");
        driver.findElement(By.xpath(".//*[@id='addlang']/a[1]")).click();

    } catch (Exception e) {
        e.printStackTrace();
    }
}
Yi Zeng
  • 32,020
  • 13
  • 97
  • 125
Amit
  • 53
  • 1
  • 1
  • 3
  • 4
    Please pay attention to the answer below, adding that capability really does cause instabilities in your tests, there's no point in even being to diagnose your issue until that setting is removed. I would also ask you kindly, to **not** use Google for your tests (unless you have a need, and I'd be interested in what it is because I would place a huge bet in that you don't necessarily **need** to be actually searching in Google's UI, there are ways around it). It is a **very** complex page. Please use a much simpler page. – Arran May 15 '13 at 08:22
  • Thanks Arran for your reply. I tried using pages other than google also but getting the same error. However, I think I have understood the problem. It's with setting the INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS capability. Thanks again.. – Amit May 16 '13 at 05:37
  • I got the same exception during using IE 11. I did not use any capability, but unfortunately I got that exception. – Ripon Al Wasim Apr 13 '16 at 11:46
  • driver.switchTo.window() is not the perfect code for this issue. – Ripon Al Wasim Apr 25 '16 at 07:33

4 Answers4

7

Remove capability INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS and manually set your IE protected mode settings to be the same for all zones.

Source:

  1. http://jimevansmusic.blogspot.com/2012/08/youre-doing-it-wrong-protected-mode-and.html

  2. NoSuchElementException is occurred during implementation of InternetExplorerDriver in Selenium WebDriver

Community
  • 1
  • 1
Yi Zeng
  • 32,020
  • 13
  • 97
  • 125
  • Thanks for your reply. Yes, I tried to set manually too but I am working in office environment and I do not have the admin rights so thats why I need to set INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, otherwise it wouldn't work. Is there any other approach? – Amit May 15 '13 at 11:15
  • 2
    You should ask your office admin that you need that changed in order for your automated tests to work, shouldn't be that hard. – aimbire May 15 '13 at 11:44
  • @Amit: The workaround is the capability, however, if that's not working, then the workaround will be to talk to your manager. What would he/she expect, if you can't control your own testing environment? – Yi Zeng May 15 '13 at 20:55
  • Thank you all for the replies. They really did help. – Amit May 16 '13 at 07:54
3
case "ie_driver":           

    //IE CODE
    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
    cap.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "https://testvmm6.partnersonline.com/vmm");
    cap.internetExplorer().setCapability("ignoreProtectedModeSettings", true);

    System.setProperty("webdriver.ie.driver", System.getProperty("user.dir")+"//exe//IEDriverServer1.exe");
    cap.setCapability("IE.binary", "C:/Program Files (x86)/Internet Explorer/iexplore.exe");
    cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    cap.setJavascriptEnabled(true);
    cap.setCapability("requireWindowFocus", true);
    cap.setCapability("enablePersistentHover", false);
jww
  • 97,681
  • 90
  • 411
  • 885
1

The issue that helped me was to set init page (IE 11 both 32 and 64)

 private WebDriver getIEDriver() {
    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, INIT_PAGE);

    File file = new File("E:/drivers/IEDriverServer.exe");
    System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
    return new InternetExplorerDriver(cap);
 }
Diana S.
  • 51
  • 1
  • 3
1

The best bet here is to make some tweaks to the registry:

  1. Go to registry edit (regedit from windows run)

  2. Look in your registry under the HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings\Zones. Over there, you should see keys number 0-4 . Under these keys 0-4, look for a value named 2500

  3. For all the keys from 0-4, have the same data for value 2500. For example, for key 0 if the value 2500 has data as 3 (hex data), then make the data for value 2500 as 3 for all the other keys (1,2,3,4).

  4. Now try to run the script.

Kurt Van den Branden
  • 11,995
  • 10
  • 76
  • 85
  • This along with the required configuration ( https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration ) worked for me. – Abdul Rahman Mar 08 '19 at 06:14