Mobile QA Zone

A Mobile Application Testing Community

 How to handle frame in WebDriver?

Views: 52

Reply to This

Replies to This Discussion

In software testing services before working on frames first we need to understand what is a frame. Frame is a part of web page which is embedded in another web page or an HTML document embedded inside another HTML document.

Below are the ways to switch over the elements in iframes using Web Driver commands:
By Index:

  • driver.switchTo().frame(0);
  • driver.switchTo().frame(1);

By Name or Id:

  • driver.switchTo().frame("iframe1");
  • driver.switchTo().frame("id of the element");

By Web Element:

  • driver.switchTo().frame(WebElement);

public static void main(String[] args) throws InterruptedException
System.setProperty("", "C://DriversC//chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.switchTo().frame("IF2"); // --> Getting into the frame., 'IF2' is the ID of the frame.
WebElement findElement = driver.findElement(By.xpath("(//a[@rel='bookmark'])[3]"));;
driver.switchTo().defaultContent(); // --> Getting out of the frame..
WebElement findElement2 = driver.findElement(By.xpath("(//img[@class=' preload-me'])[4]"));;


© 2019   Created by Anurag Khode.   Powered by

Badges  |  Report an Issue  |  Terms of Service

Welcome to Mobile QA Zone, a Next Generation Software Testing Community.Invite your friends to join this community.Write to us to become a featured member.