IFrame:
Its a Html document which is embedded in another HTML document or web page inside other webpage on a website.
>> It is used to insert the content into the webpage from different source such as advertisement.
>> IFrame can have its independent scrollbar.
>> It acts like a inline image
>> Detecting IFrame using firebug is not possible.
In a webpage we can identify the IFrames by using following methods :
>> Mouse hover over the element and press right click button on mouse, if u get an option like 'this frame' it means its a IFrame.
>> Second method is right click on the page and click on 'view page source' option and now search IFrame tag. If u get this it means page consisting IFrame.
You can identify total number of IFrames by using this:
Int size = driver.findElements(By.tagName("iframe")).size();
We can switch to IFrame using one of the following:
- By index
- By web element
- By name and id
we can switch to the IFrame by using index if there are more than one iframe.
- driver.switchTo().frame(0);
- driver.switchTo().frame(1);
>> Index of IFrame start from '0'
- If there are nested IFrames then first we must switch to outer IFrame then find total number of IFrame inside the outer frame. Now we can switch to inner IFrame by using any of known methods.
Sample code:
public class iframeHandling {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver(); //navigates to the Browser
driver.get("http://toolsqa.com/iframe-practice-page/");
driver.manage().timeouts().implicitlyWait(20L, TimeUnit.SECONDS);
driver.manage().window().maximize();
// navigates to the page consisting an iframe
driver.manage().window().maximize();
driver.switchTo().frame("IF1"); //switching the frame by ID
System.out.println(" switched to the iframe");
driver.findElement(By.xpath(".//*[@id='mobile-menu']/span[1]")).click();
//Clicks the button on iframe
driver.switchTo().defaultContent();
System.out.println("PERFORMED SUCSSESFULLY");
}
}
0 Comment(s)