- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to switch to frames in Selenium?
We can switch to frames in Selenium with the help of the following methods −
switchTo()defaultContent()
This method is for switching to and fro in between frames and parent frames. The focus is shifted to the main page.
switchTo().parentFrame()
This method is used to switch the control to the parent frame of the current frame.
Example
import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class FrameDefault { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "url with frames"; driver.get(url); driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS); //grabbing the first frame with the help of index driver.switchTo().frame(0); System.out.println("Getting the page source " + driver.getPageSource()); // switching back to the parent web page driver.switchTo().defaultContent(); driver.quit(); } }
- Related Articles
- How to switch between two frames in Tkinter?
- How to handle frames in Selenium?
- How to handle frames in Selenium with python?
- How to handle frames in Selenium Webdriver in Python?
- How to switch to new window in Selenium for Python?
- C Sharp with Selenium - How to Switch one tab to another tab in Csharp Selenium?
- How do I switch to the active tab in Selenium?
- How to count the number of frames in a page in Selenium?
- How to switch different browser tabs using Python Selenium?
- How to switch back from a frame to default in Selenium Webdriver?
- How to count the total number of frames in Selenium with python?
- How to open new tab in same browser and switch between them using Selenium?
- How to handle frames in Puppeteer?
- How to explicitly resize frames in tkinter?
- Switch tabs using Selenium WebDriver with Java.

Advertisements