I work with Selenium WebDriver. I initially open the first page then move on to the second page and perform some action and go back to the first page. In this case, I want to close the first page and work on the second. I use the command driver.close() to do this, but, it closes the second page instead of the first. How can I make Selenium to close a specific window?
Part of code
String HandleBefore = driver.getWindowHandle();
 driver.findElement(By.xpath("...")).click();
 for (String twohandle : driver.getWindowHandles()) {
        driver.switchTo().window(twohandle);
    }       
 driver.findElement(By.linkText("abc")).click();
 driver.close();