selenium-webdriver Switching Frames Switch among Child Frames of a Parent Frame.


Example

Consider you have a Parent Frame(Frame-Parent). and 2 child frames(Frame_Son,Frame_Daughter). Lets see various conditions and how to handle.

1.From Parent to Son or Daughter:

 driver.switchTo().frame("Frame_Son");
 driver.switchTo().frame("Frame_Daughter");

2.From Son to Parent: If parent is default frame, switch to default frame, else from default frame switch to parent frame. But you cannot switch directly from son to Parent.

driver.switchTo().defaultContent(); 
driver.switchTo().frame("Frame_Parent");

3.From Son to Daughter: If your sister does some mistake don't yell at her, just reach out to your Parent. Similarly, you give control to parent frame and then to daughter frame.

driver.switchTo().defaultContent(); 
driver.switchTo().frame("Frame_Parent");
driver.switchTo().frame("Frame_Daughter");