1.

How to get a number of frames on a page?

Answer»

An HTML document embedded inside the current HTML document on a web page is IFRAME. An iFrame is USED to insert content from ANOTHER source into a web page like an advertisement. A single web page can have multiple iFrames and iFrame can have an inner frame as well. The frame inside the frame is called nested frames. Content of iFrame can be changed without reloading the complete website. The IFrame is frequently used to insert content from another source into a Web page. The <iframe> tag specifies an INLINE frame.

Syntax to get number of frames on a page is -

size = driver.findElements(By.tagName("iframe")).size(); System.out.println("Total Frames --" + size); //print the number of frames on page

Here is the code to find the number of frames in a web page -

IMPORT org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class CountFrame { public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.get("https://seleniumautomationpractice.blogspot.com/2019/07/example-of-html-iframe-alternative.html"); System.out.print("No. of Frames:"); System.out.println(driver.findElements(By.tagName("frame")).size()); System.out.print(“No. of inline Frames:”); System.out.println(d.findElements(By.tagName("iframe")).size()); } }


Discussion

No Comment Found