selenium webdriver - close all child window except one particular child window using foreach (java)
<ol>
<li>Launch popuptest.com</li>
<li>Click 'Multi-PopUp Test #2 '</li>
<li>Print the number of windows opened</li>
<li>Close all the windows but not the parent window and the child window which has background color "#00C957"</li>
<li>Print the page URL and Title and the closed windows </li>
<li>Take the snapshot of the windows which are open. </li>
</ol>

<p>Please any one help me in coding:</p>

<pre><code>System.setProperty("webdriver.chrome.driver", "path + chromedriver.exe");
        ChromeDriver driver = new ChromeDriver();
        driver.get("http://popuptest.com/");
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

        String parentWindow = driver.getWindowHandle();
        System.out.println("Parent Window Session ID :" +parentWindow);
        driver.findElementByLinkText("Multi-PopUp Test #2").click();

        Set&lt;String&gt; allHandles = driver.getWindowHandles();
        System.out.println("Get All Windows :" +allHandles.size());
        for (String window: allHandles) {
        driver.switchTo().window(window);
        WebElement popwindow = driver.findElementByXPath("//body[@bgcolor='#00C957']");
          if(!window.equals(popwindow))
            {
            driver.close(); 
            System.out.println("Get Title" +driver.getTitle());
            System.out.println("Get Current URl" +driver.getCurrentUrl());*/
    }}
</code></pre>