document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /**
  2.      * Switch to  child window. If there are only two windows.
  3.      * This is method is useful if you have only two windows (Parent and Child)
  4.      */
  5.     public void switchToChildWindow()
  6.     {
  7.         String pwinhandle=driver.getWindowHandle();
  8.         Set<String> wins=driver.getWindowHandles();
  9.         for (String cwin : wins) {
  10.             driver.switchTo().window(cwin);
  11.             if (!pwinhandle.equals(cwin)) {
  12.  
  13.                 System.out.println("Switched to child window");
  14.                 break;
  15.             }
  16.             else
  17.             {
  18.                 System.out.println("Parent window");
  19.             }
  20.         }
  21.     }
');