top of page
  • Writer's picture9to5 Technologies

Working with iframes in Selenium Webdriver

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”)));

8 views0 comments

Recent Posts

See All
bottom of page