通过 Excel VBA 的 IE11 自动化 - 表单
IE11 Automation via Excel VBA - Forms
这是我最初 post . So now once logged in, I have to make two clicks to display the information I'm ultimately trying to scrape. I cannot seem to figure out the proper way to drill down to get to the clicks to work. It is all buried within a form. The 1st image shows the form structure. The 2nd image shows all of the code 的第 2 部分,我在其中试图了解主管范围内的当前情况 link。我必须使用以下内容(正如您从我之前的 post 中看到的那样)让 IE 保持连接状态,所以不确定是否有任何影响:
Dim objIE As Object
Set objIE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
为了尝试自动点击“当前情况”选项卡,我尝试了以下操作但没有成功(有和没有 0)
objIE.document.getElementById("1617")(0).Click
除了得到答案之外,我更感兴趣的是接受教育。有没有一种方法可以深入了解表单中的信息?我的印象是网页的所有元素都在加载过程中被拉入。那么这不是我对网页自动化的最低理解中的一个真正元素吗?
请注意,我必须单击“主管”才能显示其下方的树。预先感谢您的帮助!
更新:
好的,我认为这是一个重大疏忽。根据我之前的post,登录功能完美。但是一旦登录,就会创建一个新的 window。所以我相信这是挑战,对吧?它找不到任何这些 ID 或元素,因为它正在查看原始 IE 对象,而不是新的 window。那么我如何才能把它变成 activate/access 新的 window?对不起,我之前错过了!
Method getElementById
returns 单个元素,而不是集合,与例如 getElementsByClassName
不同(查看方法名称中的 "Element" 与 "Elements") .因此,不应使用 (0)
或任何其他集合索引。
正确的语法是:
objIE.document.getElementById("1617").Click
对于弹出窗口 windows 试试这个:
Dim wURL As String
Dim myWindow As Object
For Each myWindow In CreateObject("Shell.Application").Windows
wURL = myWindow.LocationURL
If InStr(wURL, "constant_part_of_popup_window_link") <> 0 Then
'do stuff
myWindow.Quit
Exit For
End if
Next myWindow
访问 iFrame 中的元素:
myWindow.document.getElementById("frameMainMenu").contentWindow.document.getElementById("1617").Click
这是我最初 post
Dim objIE As Object
Set objIE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
为了尝试自动点击“当前情况”选项卡,我尝试了以下操作但没有成功(有和没有 0)
objIE.document.getElementById("1617")(0).Click
除了得到答案之外,我更感兴趣的是接受教育。有没有一种方法可以深入了解表单中的信息?我的印象是网页的所有元素都在加载过程中被拉入。那么这不是我对网页自动化的最低理解中的一个真正元素吗?
请注意,我必须单击“主管”才能显示其下方的树。预先感谢您的帮助!
更新: 好的,我认为这是一个重大疏忽。根据我之前的post,登录功能完美。但是一旦登录,就会创建一个新的 window。所以我相信这是挑战,对吧?它找不到任何这些 ID 或元素,因为它正在查看原始 IE 对象,而不是新的 window。那么我如何才能把它变成 activate/access 新的 window?对不起,我之前错过了!
Method getElementById
returns 单个元素,而不是集合,与例如 getElementsByClassName
不同(查看方法名称中的 "Element" 与 "Elements") .因此,不应使用 (0)
或任何其他集合索引。
正确的语法是:
objIE.document.getElementById("1617").Click
对于弹出窗口 windows 试试这个:
Dim wURL As String
Dim myWindow As Object
For Each myWindow In CreateObject("Shell.Application").Windows
wURL = myWindow.LocationURL
If InStr(wURL, "constant_part_of_popup_window_link") <> 0 Then
'do stuff
myWindow.Quit
Exit For
End if
Next myWindow
访问 iFrame 中的元素:
myWindow.document.getElementById("frameMainMenu").contentWindow.document.getElementById("1617").Click