How to switch between frames in selenium

Switching between frames(also known as iframes) is possible by using driver.switchTo().frame() method in selenium. There is different options available such as index, name, id or web element to switch between frames. Following are the examples given below for switching between frames:

By using index:

Switching between frames can be done by passing zero based index to the frame in selenium. Following is the example code given below for switching frames using index:

Example code:

driver.switchTo().frame(index); //index such as 0, 1 etc.,

By using Name or ID:

Name or ID can be passed to frame for switching in selenium. Following is the example code given below for switching frame using name or id.

Example code:

driver.switchTo().frame(framename OR frameid);

By using Webelement:

Switching between frames can be possible by passing web element to frame. Following is the example code given below to switch between frames using selenium

Example code:

WebElement elem = driver.findElement(By.id(“country”));

driver.switchTo().frame(elem);

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Testingtalkslatest.com - A project by CreativeHub IT Solutions.
Contact Us At: support@testingtalkslatest.com
Our Partner websites - Classified Hub , CodesToolbox
Scroll to Top
0
Would love your thoughts, please comment.x
()
x