I am using selenium with C# to focus on an iframe which does not contain any name or id. I have tried to use an index 0 as there is only one frame on the page but I am getting the following errors:

 & Error: The given selector frame#0,iframe#0 is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: An invalid or illegal selector was specified 
 & InnerException

Any idea how I can focus on the iframe apart from these 3 options? Any help is highly appreciated.

  • What have to tried? Can we see your script? Commented Sep 27, 2016 at 6:09
  • I am using WebDriver.SwitchTo().Frame(); Commented Sep 27, 2016 at 6:20
  • Code + URL to test please.
    – FDM
    Commented Sep 27, 2016 at 9:14

2 Answers 2


If there is one iframe , it might be the window you are working on. However, you can find no. of iframes using List

List<WebElement> iframe_element=driver.finelements(By.tagName("iframe");
System.out.println("number of iframes"+iframe_elemen.size());

Then you should try hit and trial method to find out the iframe to work on using loop and you can switch to iframe using 3 ways.

switchTo.frame(int frame_number);
switchTo.frame(String frame_name);
switchTo.frame(WebElement frame_element);

This code in java though, but crux will remain the same as i only know to work on selenium with java.


To access the elements in iframe, you need to switch to that frame:

driver.switchTo().frame(id or name of the frame) 
driver.switchTo().frame(index of the frame) (Ist frame have index 0)

To move back to the normal content:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.