标题可能会令人困惑,但它不仅仅是一种印象。 我对此有一个previous post,但核心问题实际上比这更深。访问网页的框架文档,无需导航到此网页
基本上我有一个很大的代码,我从我的公司导航到一个Intranet网页(让我们把这个网页称为开始网页)。
然后我提供用户名和密码信息,然后单击“登录”按钮。点击登录按钮将在新窗口中创建一个新的网页。我们将把这个新网页称为Main网页。
主网页包含我想要获得的所有重要信息,而开始网页现在对我无用。
此处的第一个挑战是“启动”或“选择”主页面,因为“开始”页面仍处于激活状态。主网页显然有一个URL,但是不可能直接导航到这个网址,所以这就是为什么我要谈论网页的“激活”或“选择”。我设法做到这一点的帮助下,forum's post
如果您有任何疑问,请告诉我,但这不是这篇文章的问题。
所以在主网页激活的情况下,我想单击一个元素来显示更多信息。该元素嵌入在框架postfachcontent中。 见Main Page HTML document Overview和Zoom on part to click on。
在我之前提到的文章中,我试图做到这一点,但熟悉使嵌入式任务变得更加困难的元素。
与其他成员的帮助下,我想通了,可能有2种方式在postfachcontent帧获得:
通过由孩子选择子帧:
Set w = IEWindowFromLocation(path) Dim IEDoc As HTMLDocument Set IEDoc = w.document ' w is the so called Main webpage that I selected peviously in the code Dim SubFramesCollection As HTMLWindow2 Dim GoodFrame As HTMLWindow2 Dim Postfachcontent_Frame As HTMLWindow2 Set SubFramesCollection = IEDoc.frames ' the length of this is 3 since it contains the 3 main frames Set GoodFrame = SubFramesCollection(1).frames ' this contains the 2 frames of the "contentframe" frame so length = 2 Set Postfachcontent_Frame = GoodFrame(1) Doc2 = Postfachcontent_Frame.document
但是,这里的问题是,一旦我访问框架,我很困惑如何真正选择表格的元素,并点击它
- 所谓“导航”到一个新的网页,其将主网页的缩减版本仅聚焦我对如此导航到主网页URL & contentframe在框架上 .src(或postfachcontent .src)。
但这里的问题,正如我上面说的,是我不能导航到主网页上直接,所以我想我可以尝试声明一个新的InternetExplorer窗口,并给它一个位置,而无需实际导航到页面(但不幸的是它不工作)。尝试以下方法:
Set w = IEWindowFromLocation(path)
Dim IEDoc As HTMLDocument
Dim IEDok As HTMLDocument
Set IEDoc = w.document
Dim ContentFramesCollection As IHTMLElementCollection
Dim ContentFrame As HTMLFrameElement
Dim PostFachContentFramesCollection As IHTMLElementCollection
Set ContentFramesCollection = IEDoc.getElementsByName("contentframe") ' this works and returns 1 item which is the frame called contentframe, so it s a collection of element containing 1 element only
' MsgBox ContentFramesCollection.Length ' returns 1
If Not ContentFramesCollection Is Nothing Then
Set ContentFrame = ContentFramesCollection(0) ' Here we isolate the unique item contained in MainFramesCollection and store it in a single element called ContentFrame
MsgBox w.document.Location & ContentFrame.src
'On Error Resume Next
Set w2.document.Location = w.document.Location & ContentFrame.src
'MsgBox Err.Description ' returns automation error unspecified error
Set IEDok = w2.document
Set PostFachContentFramesCollection = IEDok.getElementsByName("postfachcontent")
MsgBox PostFachContentFramesCollection.Length ' returns 0...oops
End If
感谢您接触到此行,并欢迎任何帮助!
感谢您的长期投资!我正在经历这个,但当我尝试访问contentframe时,我遇到了使用queryselector的问题。返回的错误描述是_object不支持此属性或method_。到目前为止,我已经创建了一个新的模块来处理这部分,但即使通过更改可变框架的类型或在查询选择器中添加更多信息,我仍然遇到错误_运行时错误91:对象变量或With块变量不是set_.我可能需要添加一个特殊的引用来扩展属性/方法。如果我设法解决这个问题,我会告诉你。 – Seb
检查编辑后的答案(NavigateToFrame函数)。 – dee
噢好吧,我看到它的工作方式。我之前曾尝试将doc作为整个模块的私有变量声明失败,但未考虑此解决方案。不幸的是,我最怕发生的下一个错误。再次,不可能导航到主页面,当然会打开一个新页面,但是这个页面会显示一条错误消息... – Seb