Switching among windows in Selenium WebDriver

go to my blog Switching among windows:

http://www.ivst-vz.de/?debin=60-sekunden-options 60 sekunden options Selenium WebDriver assigns an alphanumeric id to each window as soon as the WebDriver object is instantiated. This unique alphanumeric id is called window handle. Selenium uses this unique id to switch control among several windows.  In simple terms, each unique window has a unique ID, so that Selenium can differentiate when it is switching controls from one window to the other.

rencontre brazzaville So Selenium has following methods to get window handles.

check out this site String parent=driver.getWindowHandle(); // It will return the current window name as a String

tchat en ligne pour rencontre Set<String> names=driver.getWindowHandles();

flirten sommer // This will return the number of windows opened by WebDriver and will return Set of Strings. Once we got the set of window names then we can iterate using Iterator.

The set is part of Java collection which allows us to handle multiple sets of data dynamically.

Consider the following scenario:

Window 1 has link “ Click Here for Signup Form” and we need to click on the link.

As soon as we click on the link Window 2 (Signup Form) displays in different window and we perform some actions on Signup Form.

Page Link: http://www.testingbar.com/multiple-window/

If you click on the link “ check that Click Here for Signup Form”, The Signup Form page (as shown in below image) will open in a new window.

http://documentalqueridowatson.es/pizdyhov/7290 Program to handle above Scenario:

package sujoy;
import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class WindowHandle {

  public static void main(String[] args) throws InterruptedException {
    // TODO Auto-generated method stub
    WebDriver driver = new FirefoxDriver();
    driver.manage().window().maximize();
  driver.get("http://www.testingbar.com/multiple-window/");
  
  driver.findElement(By.xpath("//span[contains(text(),'Click Here')]")).click();
  
  Set<String> sets = driver.getWindowHandles();
  Iterator<String> win1 =sets.iterator();
  String Parentwin = win1.next();//get the parent window ID
  String childwin = win1.next();//get the Child window ID
  
  driver.switchTo().window(childwin); //Switched to Child window
  Thread.sleep(10000);
  //Perform some action on Child window
  driver.findElement(By.xpath("//input[@name='email']")).sendKeys("Sujoy@testingbar.com");
  
  driver.switchTo().window(Parentwin); // switch back to the original window
  }
}