- 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 navigate back to current page from Frame in selenium webdriver?
We can navigate back to the current page from frame with Selenium webdriver. A frame is defined with <iframe>, <frame> or <frameset> tag in html code. A frame is used to embed an HTML document within another HTML document.
Selenium by default has access to the main browser driver. In order to access a frame element, the driver focus has to shift from the main browser window to the frame. To again focus back to the current page from frame, the method switchTo().defaultContent() is used.
Example
Code Implementation.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class SwitchBackFrame{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("https://the-internet.herokuapp.com/frames"); driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS); // identify element and click driver.findElement(By.partialLinkText("Nested")).click(); // switching to frame with frame name driver.switchTo().frame("frame-bottom"); WebElement m = driver.findElement(By.cssSelector("body")); System.out.println("Frame text: " +m.getText()); // switch from frame to main page driver.switchTo().defaultContent(); driver.close(); } }
Output
- Related Articles
- How to switch back from a frame to default in Selenium Webdriver?
- Is navigate method available in Selenium Webdriver with Python?
- Getting the URL of the current page using Selenium WebDriver.
- How to obtain the page title using Selenium webdriver?
- How to scroll down the page till page end in the Selenium WebDriver?
- How to handle frame in Selenium WebDriver using java?
- How to Scroll Down or UP a Page in Selenium Webdriver?
- How to take partial screenshot (frame) with Selenium WebDriver?
- How to set Page Load Timeout using C# using Selenium WebDriver?
- How to refresh a browser then navigate to a new page with Javascript executor in Selenium with python?
- How to know the exact time to load a page using Selenium WebDriver?
- How to scroll the Page up or down in Selenium WebDriver using java?
- Need to wait until page is completely loaded - Selenium WebDriver
- How to scroll a Web Page using coordinates of a WebElement in Selenium WebDriver?
- How to Use WebDriver Javascript Executor to Navigate to a URL using Postman?

Advertisements