I am facing issues when handling parent an child windows with selenium webdriver,
Able to switch over to child window and performed actions on child window. After performing operations in child window by clicking on "OK" button child window automatically closing. Here the problem occurring. Parent window not recognizing.
If the new window closed automatically after clicking save button on new window then i am unable to shift webdriver focus to main window.
Set<String> windows = driver.getWindowHandles();
String parent = null;
String child = null;
Iterator<String> it = windows.iterator();
while(it.hasNext())
{
parent = (String) it.next();
child = (String) it.next();
}
driver.switchTo().window(child);
driver.findElement(By.xpath("//div[@id='x-auto-32__x-auto-32_x-auto-137']/img[2]")).click();Thread.sleep(1000);
driver.findElement(By.xpath("//div[@id='x-auto-32__x-auto-32_x-auto-141']/span[2]")).click();Thread.sleep(1000);
driver.findElement(By.cssSelector("div.x-grid3-cell-inner.x-grid3-col-runStatus")).click();Thread.sleep(1000);
driver.findElement(By.xpath("//div[@id='x-auto-36']")).click();Thread.sleep(1000);
driver.findElement(By.xpath("(//button[@type='button'])[11]")).click();Thread.sleep(1000);
driver.findElement(By.id("mainForm:addinterface")).click();
driver.close();
// till this part working fine.
driver.switchTo().window(parent); // Here failing to focus on parent window and stopped to perform actions on parent window.
driver.findElement(By.id("mainForm:add")).click();
TestLogger.info("Get URL"+ driver.getCurrentUrl());
TestLogger.info("Get Window Title"+ driver.getWindowHandle());
TestLogger.info("Get URL"+ driver.getPageSource());