There are test cases in which we need to switch between multiple
windows, to automate these test cases using selenium we need to use
below functions:
1.getWindowHandle():
This function return parent window reference.
2.getWindowHandles()
: This function return all windows reference.
3.switchTo().window(Window)
: This function used to switch between windows.
Example:
String Parent_Window = driver.getWindowHandle();
for (String Child_Window : driver.getWindowHandles())
{
driver.switchTo().window(Child_Window);
driver.findElement(By.id("appointment")).click();
driver.findElement(By.id("closeAppointment")).click();
driver.close();
}
driver.switchTo().window(Parent_Window);
No comments:
Post a Comment