【问题标题】:How to access a #document(virtual document) in VBA(excel 2007)如何在 VBA(excel 2007)中访问 #document(虚拟文档)
【发布时间】:2018-08-15 12:15:14
【问题描述】:

我刚开始在 IE 中使用 vba 自动化,目前我正在尝试制定一个例程以使我的工作更轻松。为此,我必须每天早上完成一个站点。到目前为止,我设法登录了该站点并单击了一些按钮,但当我需要选择一个选项卡时却被卡住了;有 3 个选项卡,其中一个是自动选择的,实际上是第三个,我需要选择第二个(Inserimento Giustificativi):

the 3 tabs i'm talking about

接下来我会给你标签的代码:

<div id="TabContainer1_header" class="ajax__tab_header">
            <span id="TabContainer1_TabPanel3_tab" class="">
             <span class="ajax__tab_outer">
              <span class="ajax__tab_inner">
               <span id="__tab_TabContainer1_TabPanel3" class="ajax__tab_tab">Console Operativa</span>
              </span>
             </span>
            </span>
            <span id="TabContainer1_TabPanel1_tab" class="">
             <span class="ajax__tab_outer">
              <span class="ajax__tab_inner">
               <span id="__tab_TabContainer1_TabPanel1" class="ajax__tab_tab">Inserimento Giustificativi</span>
             </span>
            </span>
           </span>
           <span id="TabContainer1_TabPanel2_tab" class="ajax__tab_active">
            <span class="ajax__tab_outer">
             <span class="ajax__tab_inner">
              <span id="__tab_TabContainer1_TabPanel2" class="ajax__tab_tab">Giustificativi Generici</span>
             </span>
            </span>
           </span>
</div>

这是我到现在为止的代码(真的很基本):

Sub SearchBot()

    Dim objIE As InternetExplorer
    Dim ele As Object

    Set objIE = Nothing

    Set objIE = New InternetExplorer

    objIE.Visible = True

    objIE.navigate "sia.comdata.it/opera"

    Application.Wait (Now + TimeValue("00:00:05"))

    objIE.document.getElementById("UserName").Value = "username"

    objIE.document.getElementById("Password").Value = "$password"

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

    Application.Wait (Now + TimeValue("00:00:05"))

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

    Application.Wait (Now + TimeValue("00:00:02"))

    objIE.document.getElementById("content_GestioneOperativo").getElementsByTagName("a")(2).Click

    Application.Wait (Now + TimeValue("00:00:30"))

End Sub

我尝试了上述所有方法,并且已经在互联网上搜索了一周的解决方案但没有任何解决方案,我一直收到错误运行时错误 91 或不支持该操作。

我还注意到,当手动单击其中一个选项卡时,ClassName“ajax__tab_active”会自行移动到我选择的标签的类,并且填充有“ajax__tab_active”的 ClassName 保持空白,我不知道它是否有帮助,只是我觉得很奇怪。

任何提示都会有所帮助,因为我是一个初学者,我真的不知道还有什么可以尝试的,因为我在这里写,

谢谢。

*我正在编辑我的问题,因为做了更多尝试,我注意到我无法访问部分源代码。在源代码的某个时刻,有一个名为 iframe 的标签,紧随其后是 #document,似乎我无法以任何方式访问 #document 下的任何内容,谷歌搜索我知道它是嵌入在源代码中的虚拟文档代码,但我仍然不知道如何访问它:

Virtual document

这就是源代码的外观,选择的行是我需要得到的,

谢谢。

【问题讨论】:

  • 要定位选项卡,您可以使用GetElementByTag("span") 和属性InnerText 来定位InnerText 为Inserimento Giustificativi 的选项卡。然后,也许点击会起作用?
  • 我觉得这可能是一个 X-Y Problem备份一点,您能否详细解释一下您实际上想要做什么,例如“最终目标”?
  • 首先感谢您的回答。 foxfire 我尝试了你给我的提示: Set ele = objIE.document.getElementsByTagName("span") For Each span In ele If ele.innerText = "Inserimento Giustificativi" Then ele.Click End If Next 但它给了我不支持该操作的错误,我写错了吗?
  • 你的答案 ashleedawng。我不确定您要解决什么问题,但该例程的最终目标是选择一些名称(这些名称将出现在我无法弄清楚如何选择的选项卡中)并且对于这些名称,我需要填写一些框使用我从另一个 excel 文件中获取的数据(例如,当他上班时 es:08:00 以及他在工作中待了多少小时 es:04:00),然后我必须单击另一个按钮来验证插入的数据在盒子里。

标签: html vba excel internet-explorer web-scraping


【解决方案1】:

我设法解决了这个问题。 为了能够访问#document 下的数据,似乎我所要做的就是登录然后导航到该站点上方的一行,即:https://sia.comdata.it/opera/GestioneOperativo/Giustificativi.aspx,之后一切顺利。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    • 1970-01-01
    • 2016-08-23
    • 1970-01-01
    • 1970-01-01
    • 2012-07-04
    相关资源
    最近更新 更多