How to work with Window and Frames in Selenium WebDriver

In this article we will see the methods to work with Window and Frame(IFRAME elements) in selenium web driver. I use c#(VS2010).

-To switch focus to another window by its Name.
 driver.SwitchTo().Window("The name of the window to select");
Note : If we want to switch the focus, then we use this. Mostly used when we need to change one window to another. The name is in string format for the title of the window.

-To switch focus to another frame by Zero based Index
driver.SwitchTo().Frame(0);
 -To switch focus to another frame by its name or ID
driver.SwitchTo().Frame("ID");
-To switch focus to An OpenQA.Selenium.IWebDriver frame.( an object of IWebDrive)
driver.SwitchTo().Frame(element);
Note : In hear, element is a IWebElement type object. Actually its a real web element. For the element object finding, I use
private IWebElement element; // declaring element, outside of method

And for switch frame parameter, I use this
element = driver.FindElement(By.XPath("Xpath Location"));
driver.SwitchTo().Frame(element);
Note: Xpath location is one of the popular way to identify web elements accurately.

-To switch focus to currently focused element OR the body element [if no element focused]
driver.SwitchTo().ActiveElement();

-To Select either the first frame on the page or the main document when a page contains iFrames
driver.SwitchTo().DefaultContent();

-To switch to the currently active modal dialog
driver.SwitchTo().Alert();

...to be continued... thanks..:)