top of page

Working with iframes in Selenium Webdriver

  • Writer: 9to5 Technologies
    9to5 Technologies
  • Dec 9, 2019
  • 1 min read

Suppose you have html like this:

  1. If iframe has name or id, then use: driver.switchTo().frame(name_or_id)

  2. If page contains only one or two iframes then we can use this method: driver.switchTo().frame(index) or If you have only one iframe in the page, try driver.switchTo().frame(0)

  3. You can also switch to iframe by finding its CSS/Xpath/id. Syntax is: driver.switchTo().frame(iframe_element) By using cssSelector:

  • driver.switchTo().frame(driver.findElement(By.cssSelector(“iframe[src=’path of iframe”)));

  • driver.switchTo().frame(driver.findElement(By.cssSelector(“iframe[title=’title of the iframe’]”)));

  • driver.switchTo().frame(driver.findElement(By.tagName(“iframe”)));

Recent Posts

See All

Comments


bottom of page