0

How to select/switch to an Iframe (as the currently targeted document) in Firefox through selenium webdriver. What are the different ways to select an iframe with/ without webdriver.

driver.switchTo.frame("FrameID");
xxxmatko
  • 4,017
  • 2
  • 17
  • 24
  • Possible duplicate of [How to handle iframe in WebDriver](https://stackoverflow.com/questions/9942928/how-to-handle-iframe-in-webdriver) – JeffC Sep 12 '17 at 13:47

2 Answers2

0

Try this sample example:

   WebElement iframeElement = driver.findElement(By.id("IF1"));

    //now use the switch command
    driver.switchTo().frame(0);

   //You can use iFrame name
   //driver.switchTo().frame(iframeElement);

    //Switch to parent window
    driver.switchTo().defaultContent();
    driver.quit();

Follow this link to understand more:

http://toolsqa.com/selenium-webdriver/handling-iframes-using-selenium-webdriver/

iamsankalp89
  • 4,607
  • 2
  • 15
  • 36
0

You can actually select an iFrame using the below methods: -

  • frame(index)
  • frame(Name of Frame [or] Id of the frame)
  • frame(WebElement frameElement)
  • defaultContent()

So you can switch by passing the any above information about the frame. Yes you need to switch everytime according to require action

Example in c#:-

driver.SwitchTo().Frame("top");

.... Perform your action on frame

driver.SwitchTo().defaultContent();

driver.SwitchTo().Frame("navigation");

.... Perform your action on frame

driver.SwitchTo().defaultContent();

....

Now you have to find the hierarchy of your nested frame and switch all one by one.

use chrome dev tools and select the element you can see the hierarchy .. just switch from parent to child till your element not reach. perform your operation and switch back to default

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125