How to identify and switch to the frame in selenium webdriver when frame does not have id

driver.switchTo().frame() has multiple overloads.

  1. driver.switchTo().frame(name_or_id)

    Here your iframe doesn’t have id or name, so not for you.

  2. driver.switchTo().frame(index)

    This is the last option to choose, because using index is not stable enough as you could imagine. If this is your only iframe in the page, try driver.switchTo().frame(0)

  3. driver.switchTo().frame(iframe_element)

    The most common one. You locate your iframe like other elements, then pass it into the method.

Here locating it by title attributes seems to be the best.

driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[title="Fill Quote"]")));
// driver.switchTo().frame(driver.findElement(By.xpath(".//iframe[@title="Fill Quote"]")));

Leave a Comment