int i = WebDriver.WindowHandles.Count;
if (i > 1)
{
//switch to child window
WebDriver.SwitchTo().Window(WebDriver.WindowHandles[1]);
//switch to parent window
WebDriver.SwitchTo().Window(WebDriver.WindowHandles[0]);
}
Try this to switch to diff window handles and coming back to parent window
String winHandleBefore = driver.getWindowHandle();
for(String winHandle : driver.getWindowHandles())
{
driver.switchTo().window(winHandle);
}
for (String handle1 : driver.getWindowHandles())
{
driver.switchTo().window(handle1);
}
// your code here
driver.switchTo().window(winHandleBefore); //switch to parent window