我正在为一个遗留应用程序编写测试,其中主文档中有一个 iFrame,然后在其中有另一个 iFrame.所以层次结构是:
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
这是我的代码(我使用的是 C#)
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"));
问题是,我无法到达第二级 iFrame,即 contentIFrame
The problem is, I am unable to reach the 2nd level iFrame i.e. contentIFrame
有什么想法吗?
我目前正在一个类似的网站上进行测试.(主文档内的嵌套 iframe)
I'm currently testing on a similar website. (nested iframes inside the main document)
<div>
<iframe>
<iframe><iframe/>
<iframe/>
</div>
您好像没有使用帧切换方式 在 Api 中提供.这可能是问题所在.
It seems that you are not using the frame switching method provided in Api. This could be the problem.
这就是我正在做的,对我来说效果很好.
//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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!