Can not switch to the Parent window after selecting a value in the Child window using selenium

advertisements

I used the below code to switch the window to child window and select a radio-button and switch back to parent window to select few values,but after selecting a value in the child window it doesn't allow me to select a value in the parent window

It says "unable to locate element"

fd.findElementByXPath("//*[@id='image22']").click();
String parentwindowRMU=fd.getWindowHandle();
Set<String> handles1=fd.getWindowHandles();
for(String Windowhandles1:handles1)
{
   if(!Windowhandles1.equals(parentwindowRMU))
   {
       fd.switchTo().window(Windowhandles1);
       Thread.sleep(7000);
       fd.findElementByXPath("//*[@id='radio1']").click();

       fd.findElementByXPath("//*[@id='ext-gen31']").click();
       Thread.sleep(5000);
       break;
   }
}
fd.switchTo().window(parentwindowRMU);


Use iterator and a while loop to store the various window handles and then switch back and forth.

//Click your link
    driver.findElement(By.xpath("xpath")).click();
    //Get all the window handles in a set
    Set <String> handles =driver.getWindowHandles();
    Iterator<String> it = handles.iterator();
    //iterate through your windows
    while (it.hasNext()){
    String parent = it.next();
    String newwin = it.next();
    driver.switchTo().window(newwin);
    //perform actions on new window
    driver.close();
    driver.switchTo().window(parent);
                        }