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();
    }
}
4
  • 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. Commented May 15, 2013 at 8: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.. Commented May 16, 2013 at 5:37
  • I got the same exception during using IE 11. I did not use any capability, but unfortunately I got that exception. Commented Apr 13, 2016 at 11:46
  • driver.switchTo.window() is not the perfect code for this issue. Commented Apr 25, 2016 at 7:33

4 Answers 4

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

Sign up to request clarification or add additional context in comments.

4 Comments

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?
You should ask your office admin that you need that changed in order for your automated tests to work, shouldn't be that hard.
@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?
Thank you all for the replies. They really did help.
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);

3 Comments

Please add explanations to your answers.
Please add little description
Please set the protected mode of IE instead of using cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
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);
 }

1 Comment

I wrote as: cap.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "google.com/");
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.

1 Comment

This along with the required configuration ( github.com/SeleniumHQ/selenium/wiki/… ) worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.