- 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 handle frames in Selenium?
We can handle frames in Selenium with the help of following methods −
switchTo().frame( frameNumber)
This method uses the frame id as the parameter. The index of frame id starts from 0. NoSuchFrameException is thrown if the frame is not found.
switchTo().frame( frameName)
This method uses the frame name as defined by the developer as the parameter. The frame name is considered a String and is enclosed in quotes. NoSuchFrameException is thrown if the frame is not found.
switchTo().frame( WebElement)
This method uses the webelement as the parameter. NoSuchFrameException is thrown if the frame is not found. StaleElementReferenceException if the frame is no longer active.
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 FrameSet { 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); //grabbing the frame with the help of frame name driver.switchTo().frame(“<<name expression>>“); //grabbing the frame with the help of frame webelement WebElement name = driver.findElement(By.name(“frame-right”)); driver.switchTo().frame(driver.findElement(By.name(“<<name expression”))); driver.quit(); } }
- Related Articles
- How to handle frames in Selenium with python?
- How to handle frames in Selenium Webdriver in Python?
- How to handle frames in Puppeteer?
- How to switch to frames in Selenium?
- How to Handle alerts in Selenium?
- How to handle popup windows in Selenium?
- How to handle chrome notification in Selenium?
- How to handle proxy in Selenium in Java?
- How to handle web based alerts in Selenium?
- How to handle frame in Selenium WebDriver using java?
- How to handle child windows in Selenium with python?
- How to count the number of frames in a page in Selenium?
- How to count the total number of frames in Selenium with python?
- How to handle windows file upload using Selenium WebDriver?
- How to handle SSL certificate error using Selenium WebDriver?

Advertisements