【发布时间】:2016-11-10 14:06:46
【问题描述】:
标题可能令人困惑,但这不仅仅是一种印象。 我有一个 previous post 关于这个,但核心问题实际上比这更深。
基本上,我有一个大代码,我在其中导航到我公司的 Intranet 网页(我们将此网页称为 Start 网页)。
然后我提供用户名和密码信息并单击“登录”按钮。单击登录按钮将在新窗口中创建一个新网页。我们将这个新网页称为主网页。
主网页包含我想获得的所有重要信息,而开始网页现在对我来说毫无用处。
这里的第一个挑战是“激活”或“选择”主网页,因为“开始”网页仍处于激活状态。主网页显然有一个 URL,但无法直接导航到它,所以这就是我谈论网页的“激活”或“选择”的原因。在forum's post的帮助下,我设法做到了这一点
如果您对此有任何疑问,请告诉我,但这不是这篇文章的问题。
因此,激活主网页后,我想单击一个元素以显示更多信息。该元素嵌入在框架postfachcontent 中。 请参阅Main Page HTML document Overview 和Zoom on part to click on。
在我上面提到的上一篇文章中,我尝试过这样做,但熟悉了使任务变得更加困难的“嵌入式”元素。
在其他成员的帮助下,我发现有两种方法可以进入 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
感谢您到达那条线,欢迎任何帮助!
【问题讨论】:
标签: html windows vba internet-explorer