What is an IFrame ?
IFrame is an inline frame used for displaying external objects or elements from different webpages into a container. IFrame is nothing but an empty container which we can use various HTML controls in it. Whenever we want to display a partition or a segment like
Login form, or Registration form with different functionalities, we use iframes.
Syntax for IFrame
- <iframe src="Path of the html page" height="100" width ="100" frameborder=''0" ><iframe>
From the above syntax, we can set the height and width of the iframe by giving the certain values based on our requirement.
By default, every iframe will be displaying with certain border. If we want to hide the border or if we don't want to show the iframe when the page loads, then we need to set frameborder="0". So, when the page loads, only controls will be visible within the iframe. As we know when using automation tools like Selenium, we can execute or automate anything which is available on the webpage. Automating or executing the controls available on the webpage is an easy task. The complexity comes when there is a frame with various controls. Each frame acts as a container, or we can say as panel, with multiple controls.
If there are controls available directly on the webpage rather than div or Frames or panel, then it will be easier to automate any control using Selenium Webdriver; but suppose there are some scenarios where controls are available in frames such as iframe1, iframe2 or so on, then there will be some difficulty in identifying the controls.
In order to execute or automate it, first we need to identify whether there is any frame available on the webpage or not. If the frame exists on the webpage, then with the frame properties like Id, Name, ClassName,Tagname etc. we need to identify the frame. Once the frame is identified, enter into the frame by using SwitchTo().Frame() method, and identify each control with their properties so as to automate them.
Example