I have written the following code to open a google map window get it's url then close it and perform the actions on my previous window:
try
{
String winHandleBefore = driver.getWindowHandle();
element("icon_google_map").click();
for(String winHandle : driver.getWindowHandles())
{
driver.switchTo().window(winHandle);
}
Thread.sleep(9000);
String currentURL = driver.getCurrentUrl();
logMessage(currentURL);
String expectedURL="xyz";
Assert.assertEquals(currentURL, expectedURL);
logMessage(currentURL);
driver.close();
driver.switchTo().window(winHandleBefore);
return true;
}
catch(Exception e)
{
return false;
}
The code above opens the map window but does not close it,instead it shows the following error when i perform the action on previous window.
Error: org.openqa.selenium.NoSuchWindowException: no such window: target window already closed