After the point wherein you opened a new window, I think you would need to do a driver.getWindowHandles() which would list out the window handles of all the open windows, then find your window that needs to be closed, switch over to it and close it off.
Something like this (This is crashing my firefox, which I would need to figure out why :) but this is something that can help you get started )
FirefoxDriver driver = new FirefoxDriver();
driver.findElement(By.xpath("//a[@id='helpLnk']")).click();
String currentWindow = driver.getWindowHandle();
driver.findElement(By.xpath("//a[text()='sign-in help']")).click();
Set<String> s = driver.getWindowHandles();
Iterator<String> iterators = s.iterator();
String nameOrHandle = null;
while (iterators.hasNext()){
String id = iterators.next();
System.out.println(id);
if (! currentWindow.equalsIgnoreCase(id)){
nameOrHandle = id;
}
}
System.out.println(driver.getTitle());
driver.switchTo().window(nameOrHandle).close();
System.out.println(driver.getTitle());
driver.quit();
Thanks & Regards
Krishnan Mahadevan
"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"