How to handle iFrames in C# using Selenium web driver?
In C# Automation using Selenium, we can handle frames using the below ways:
1. Using
ID attribute
Example:
driver.SwitchTo().Frame("title"); //where id=title
2.
Using
list of Web-elements having same iframe tags
Example:
IList<IWebElement> iframe =
driver.FindElements(By.TagName("iframe"));
3.
Using
index
Examples:
driver.SwitchTo().Frame(1);
driver.SwitchTo().Frame(0);
4.
Switching
back to Main page from Frame
Examples:
driver.SwitchTo().ParentFrame();
driver.SwitchTo().DefaultContent();
driver.SwitchTo().Window(parentWindow);
Sample Program Syntax:
public void iFrameIn(IWebDriver driver)
{
driver.SwitchTo().Frame(0); //using index
}
public void iFrameOut(IWebDriver driver)
{
driver.SwitchTo().DefaultContent(); //switching back
}
About the author of this post:
I am a Software Test Engineer, who is quite passionate about testing and finding bugs. I am from Bangalore, India.

