通过Excel VBA进行IE11自动化-表单 [英] IE11 Automation via Excel VBA - Forms

查看:384
本文介绍了通过Excel VBA进行IE11自动化-表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我原始帖子这里.因此,现在登录后,我必须单击两次以显示最终要抓取的信息.我似乎无法找出适当的方法来进行深入挖掘,以使点击生效.它全都埋在表格中.第一张图片显示了表单结构.第二张图片显示了所有代码主管范围下方的情境链接.我不得不使用以下内容(如您从前一篇文章中看到的)来使IE保持连接状态,因此不确定是否会产生任何影响:

This is part 2 from my original post here. 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 where I'm trying to get to the Current Situation link below the Supervisor span. I had to use the following (as you see from my previous post) to get IE to stay connected so not sure if that has any impact:

Dim objIE As Object

Set objIE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")

在尝试使当前情况"选项卡单击自动化时,我尝试了以下操作,但没有运气(有和没有0)

In an attempt to automate the Current Situation tab click, I've tried the following with no luck (with and without the 0)

objIE.document.getElementById("1617")(0).Click

除了获得答案之外,我对受教育更感兴趣.有没有一种方法可以细化表单中的信息?我的印象是网页的所有元素在加载过程中都被拉入.那么,在我对网页自动化的最低了解中,这不是真正的元素吗?

I'm more interested in getting educated in addition to getting an answer. Is there a method to drilling down into information within a form? I was under the impression that ALL the elements of a webpage were pulled in during loading. So is this not truly an element in my minimal understanding with webpage automation?

请注意,我必须单击主管"以显示其下方的树.预先感谢您的帮助!

As a note, I do have to click Supervisor to get the tree below it to display. Thanks in advance for your help!

更新: 好吧,我认为这是一个重大的疏忽.根据我之前的帖子,登录功能非常完善.但是一旦登录,就会创建一个新窗口.所以我认为这是挑战,对吗?它找不到这些ID或元素中的任何一个,因为它正在查看原始IE对象,而不是新窗口.那么,如何获得它来激活/访问新窗口?抱歉,我早些错过了!

UPDATE: Ok a major oversight here I think. Based on my previous post, the login functions perfectly. But once logged in, a new window gets created. So I believe that is the challenge, right? It can't find any of these IDs or Elements because it's looking at the original IE object, not the new window. So how do I get it to activate/access the new window? Sorry I missed that earlier!

推荐答案

方法getElementById返回单个元素,而不是集合,与例如getElementsByClassName不同(请在方法名称中查看元素"与元素") .因此,不应使用(0)或任何其他collection索引.

Method getElementById returns a single element, not a collection, unlike for example getElementsByClassName (look at "Element" vs "Elements" in method name). Therefore (0) or any other index of collection should not be used.

正确的语法是:

objIE.document.getElementById("1617").Click

对于弹出窗口,请尝试以下操作:

For pop-up windows try this:

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中的元素:

For accessing an element within iFrame:

myWindow.document.getElementById("frameMainMenu").contentWindow.document.getElementById("1617").Click

这篇关于通过Excel VBA进行IE11自动化-表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆