iFrames in Selenium are also referred as the inline frame. An inline frame is used to embed any other document within the current/parent HTML document using <iframe></iframe> tags.
Iframes are mainly utilized to insert data from different external sources. For example, if a third party advertisement is displayed on a web page and we need to move that advertisement to a specific position, it can be accomplished using iframe.
SwitchTo().frame method primarily enables the browser to switch between multiple frames. SwitchTo() can be implemented in the following ways:
Example -
WebElement element = driver.findElement(By.id("IFrame1")); switchTo.frame(element);After performing different operations on a particular page, we can switch back to the main page using - switchTo().defaultContent();
We can also use the default method in the ExpectedCondition class to switch on any iframe (if a particular frame is not found then NoSuchFrameException will be thrown):