Finding nested iFrame using Selenium 2(使用 Selenium 2 查找嵌套的 iFrame)
问题描述
我正在为一个遗留应用程序编写测试,其中主文档中有一个 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Selenium 2 查找嵌套的 iFrame
![](/xwassets/images/pre.png)
![](/xwassets/images/next.png)
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01