Tuesday, 21 June 2016

Switching to default content in Selenium

A browser window can have multiple frames inside it. A frame can have multiple child frames inside it.

Suppose there are 2 frames with names f1 and f2 at the top level. There is one child frame with name cf1 inside frame f1. To switch to frame cf1, you will have to use 2 lines of code.

//After below statement is executed, context is switched to frame - f1

driver.switchTo.frame("f1");

//Now we are inside frame f1. To switch the context to child frame - cf1, we will have to use below command.

driver.switchTo.frame("cf1");

Now we are inside frame cf1.  

To switch the context to default content (main window content), you can use below line.

driver.switchTo().defaultContent();

Notice that while switching to the child frame - cf1, we have to switch the context to each parent frame. But to switch the context to main window, we can directly use defaultContent() method.



What do you think on above selenium topic. Please provide your inputs and comments. You can write to me at reply2sagar@gmail.com

No comments:

Post a Comment

Buy Best Selenium Books