top of page
Search

Working with iframes in Selenium Webdriver

  • qatestingthreesixt
  • Dec 1, 2021
  • 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


Contact Us

PR World Trade Center, 108, near bus stand, Jalandhar, Punjab 144001

Phone or Whatsapp

+91-7652933997

     

bottom of page