Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am writing tests for a legacy application in which there is an iFrame within the main document, and then another iFrame within that. So the hierarchy is:

Html Div (id = tileSpace)
  iFrame (id = ContentContainer)
    iFrame (id = Content)
      Elements

This is my code (I am using C#)

RemoteWebDriver driver = new InternetExplorerDriver();
var tileSpace = driver.FindElement(By.Id("tileSpace"));
var firstIFrame = tileSpace.FindElement(By.Id("ContentContainer"));
var contentIFrame = firstIFrame.FindElement(By.Id("Content"));

The problem is, I am unable to reach the 2nd level iFrame i.e. contentIFrame

Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
238 views
Welcome To Ask or Share your Answers For Others

1 Answer

I'm currently testing on a similar website. (nested iframes inside the main document)

<div>
    <iframe>
        <iframe><iframe/>
    <iframe/>
</div>

It seems that you are not using the frame switching method provided in Api. This could be the problem.

Here is what I'm doing, it works fine for me.

//make sure it is in the main document right now
driver.SwitchTo().DefaultContent();

//find the outer frame, and use switch to frame method
IWebElement containerFrame = driver.FindElement(By.Id("ContentContainer"));
driver.SwitchTo().Frame(containerFrame);

//you are now in iframe "ContentContainer", then find the nested iframe inside
IWebElement contentFrame = driver.FindElement(By.Id("Content"));
driver.SwitchTo().Frame(contentFrame);

//you are now in iframe "Content", then find the elements you want in the nested frame now
IWebElement foo = driver.FindElement(By.Id("foo"));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...