gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 13:06:31 25 4
gpt4 key购买 nike

我需要从嵌套在两个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com