发现使用Selenium 2嵌套iframe [英] Finding nested iFrame using Selenium 2

查看:166
本文介绍了发现使用Selenium 2嵌套iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写,其中有在主文档中的iFrame,然后于另一个的iFrame的遗留应用的测试。所以层次是:



  HTML DIV(ID = tileSpace)
的iFrame(ID = ContentContainer)
的iFrame(ID =内容)
元素

这是我的代码(我使用C#)

  RemoteWebDriver司机=新InternetExplorerDriver(); 
VAR tileSpace = driver.FindElement(By.Id(tileSpace));
VAR firstIFrame = tileSpace.FindElement(By.Id(ContentContainer));
VAR contentIFrame = firstIFrame.FindElement(By.Id(内容));



现在的问题是,我无法达到第二级的iFrame即contentIFrame



任何想法?


解决方案

我目前正在测试一个类似的网站。 (主文档中在嵌套的iframe)



<预类=郎HTML prettyprint-覆盖> < D​​IV>
< IFRAME>
< IFRAME>< IFRAME />
< IFRAME />
< / DIV>



看来你不使用的帧切换方法 中提供的API。这可能是问题。



这是我在做什么,它为我工作得很好。



<预类=郎-CS prettyprint-覆盖> //确保它是在主文档中,现在
driver.SwitchTo()DefaultContent()。

//找到外框,并用开关框架方法
IWebElement集装箱= driver.FindElement(By.Id(ContentContainer));
driver.SwitchTo()框架(集装箱)。

//你现在在IFRAMEContentContainer,然后找到$ B $里面嵌套iframe b IWebElement contentFrame = driver.FindElement(By.Id(内容));
driver.SwitchTo()框架(contentFrame)。

//你现在在iframe的内容,然后找到在嵌套框架你想要的元素,现在
IWebElement富= driver.FindElement(By.Id(富)) ;


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?

解决方案

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"));

这篇关于发现使用Selenium 2嵌套iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆