

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 back from a frame to default in Selenium Webdriver?
We can switch back from a frame to default in Selenium webdriver using the switchTo().defaultContent() method. Initially, the webdriver control remains on the main web page.
In order to access elements within the frame, we have to shift the control from the main page to the frame with the help of the switchTo().frame and pass the frame name/id or webelement of the frame as a parameter to that method.
Finally, again we can switch the control to the main page with the switchTo().defaultContent() method. A frame is identified in the html code with the tag names – frame, iframe or frameset.
Let us identify the text Iframe which is inside a frame and the text click on the below link − which is outside a frame
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; public class FrameDefaultSwitch{ public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); //implicit wait driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //URL launch driver.get("http://www.uitestpractice.com/Students/Switchto"); // switch to frame driver.switchTo().frame("iframe_a"); //identify element inside frame WebElement d = driver.findElement(By.tagName("h1")); System.out.println("Text inside frame: " + d.getText()); //switch to default driver.switchTo().defaultContent(); //identify element outside frame WebElement e = driver.findElement(By.tagName("h3")); System.out.println("Text outside frame: " + e.getText()); driver.quit();} }
Output
- Related Questions & Answers
- How to navigate back to current page from Frame in selenium webdriver?
- How to set Selenium Python WebDriver default timeout?
- How to handle frame in Selenium WebDriver using java?
- Switch tabs using Selenium WebDriver with Java.
- How to take partial screenshot (frame) with Selenium WebDriver?
- How to switch to frames in Selenium?
- How to Select Value from DropDown using Selenium Webdriver?
- How to handle frame in WebDriver?
- How to record a video in Selenium webdriver?
- How to get typed text from a textbox by using Selenium Webdriver?
- How to Select date from a datepicker with Selenium Webdriver using Python?
- How to capture the text from Alert Message in Selenium Webdriver?
- How to retrieve value from an edit box using Selenium webdriver?
- How to switch to new window in Selenium for Python?
- How to open a new tab using Selenium WebDriver?
Advertisements