c# - 使用 XPath 和 C# 移动多个 iFrame

标签 c# html iframe xpath selenium-webdriver

我需要从嵌套在两个 iframe 中的表中获取数据元素。帧显示为:

<iframe id="appContent" frameborder="0" name="appContentFrame" src="/controller.aspx" style="height: 0px; width: 1319px;">
       //....
            <iframe id="childFrame" frameborder="0" src="javascript:"";" onload="AjaxDocument.registerFrames('childFrame');" name="childFrame">

我正在尝试使用以下方法选择两个框架:

 driver.SwitchTo().Frame("appContent");
 driver.SwitchTo().Frame("childFrame");

我第一次使用它们时调用成功,但是当我第二次调用它们时,在我加载一个新网页后,找不到它们。我在程序中早些时候使用了这些相同的调用,在该程序中我在另一个具有相同名称的 iframe 的网页上输入数据。有没有可能我不能再次调用它们的原因是因为两组调用都在同一代码范围内?

最佳答案

可能的原因是你没有切换回父级。当你在第一个 iframe 中完成工作后,执行一个 driver.SwitchTo().DefaultContent() ,这将带你回到上一帧并对上层执行相同的操作iframe 再次出现。

编辑

在 C# 上查找正确的 API 文档很痛苦。然而,这些是用于切换帧的两种重要方法的最简洁的定义。

driver.SwitchTo().ParentFrame();

Select the parent frame of the currently selected frame.

driver.SwitchTo().DefaultContent();

Switches to the element that currently has the focus, or the body element

引用this

关于c# - 使用 XPath 和 C# 移动多个 iFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30627465/

相关文章:

c# - 编译器琐事 : What is consequence of this code

c# - 如何在 C# 中将 1700 格式化为 1'700 and 1000000 to 1' 000'000?

javascript - 从 map 中选择表行。 Angular/Google map 集成

javascript - 使 HTML 表格的数据响应

c# - SSH.NET 上传整个文件夹

c# - 实现哈希的最佳实践?

javascript - 如何让Javascript改变样式?

iframe - 跨域资源共享 header 可以授权X域IFRAME访问吗?

javascript - IE中动态iFrame的正确访问

html - iFrame 禁止一起滚动