无法从vb6从托管ie浏览器获取htmlelement

时间:2016-08-15 15:04:17

标签: vb6

我正在修改IE自动化程序 我试图从现有的vb6程序中获取html页面中的单击html元素。

我能够获得除下面的下拉按钮菜单之外的所有元素,如下图所示

Example Htmlpage

当我点击"操作"下拉菜单,然后单击菜单项"导出到Excel"或doc.activeelement.innertext返回的任何其他菜单" Actions"而不是"导出到Excel"

这是我的VB代码

Public WithEvents IE As InternetExplorer
Private WithEvents doc As HTMLDocument
Private Function Doc_onclick() As Boolean
    me.grid1.cell(1,j)=doc.activeelement.tagname & "::" doc.activeelement.innertext 
    Doc_onclick = True
End Function

以下是HTML代码呈现所述页面的下拉菜单的相关部分



<div id="pt1:USma:0:MAt1:0:pt1:r1:0:AP1:r8:0:AT1:_ATp:j_id12" class="x6e" style="overflow: hidden; width: 167px;">
  <div class="xde">
    <div id="pt1:USma:0:MAt1:0:pt1:r1:0:AP1:r8:0:AT1:_ATp:j_id12::oc" class="af_menuBar_content">
      <table border="0" cellpadding="0" cellspacing="0" summary="">
        <tr>
          <td class="x19v">
            <a style="display: none;"></a>
            <div id="pt1:USma:0:MAt1:0:pt1:r1:0:AP1:r8:0:AT1:_ATp:ATm" _afrdth="1" _afrgrp="0" class="xg2 xkj">
              <div class="x1b7" tabindex="0">
                <table border="0" cellpadding="0" cellspacing="0" summary="">
                  <tr>
                    <td></td>
                    <td class="x19w">
                      <a class="xfn" href="#" onclick="return false" tabindex="-1">
									Actions</a>
                    </td>
                    <td>
                      <div class="xg3">
                      </div>
                    </td>
                  </tr>
                </table>
              </div>
              <table id="pt1:USma:0:MAt1:0:pt1:r1:0:AP1:r8:0:AT1:_ATp:ATm::menu" border="0" cellpadding="0" cellspacing="0" class="x1a7" style="display: none;" summary="">
                <tr>
                  <td id="pt1:USma:0:MAt1:0:pt1:r1:0:AP1:r8:0:AT1:_ATp:ATm::sUpBg" class="x26x p_AFDisabled">
                    <div id="pt1:USma:0:MAt1:0:pt1:r1:0:AP1:r8:0:AT1:_ATp:ATm::ScrollUp" class="x1a8 p_AFDisabled" style="display: none">
                      <span class="x1aa"></span>
                    </div>
                  </td>
                </tr>
                <tr>
                  <td>
                    <div id="pt1:USma:0:MAt1:0:pt1:r1:0:AP1:r8:0:AT1:_ATp:ATm::ScrollBox" class="x1ba">
                      <table id="pt1:USma:0:MAt1:0:pt1:r1:0:AP1:r8:0:AT1:_ATp:ATm::ScrollContent" border="0" cellpadding="0" cellspacing="0" class="af_menu_scroll-content" summary="" width="100%">
                        <tr id="pt1:USma:0:MAt1:0:pt1:r1:0:AP1:r8:0:AT1:_ATp:editMenuItem" _afrdth="2" _afrgrp="0" class="x1a2 x1ab p_AFDisabled" onclick="return false;">
                          <td class="x1ae">
                            <div class="x1bb">
                            </div>
                          </td>
                          <td class="x1af">Edit Supplier</td>
                          <td class="x1ag">
                            <div class="x1bb">
                            </div>
                          </td>
                          <td class="x1ah">
                            <div class="x1bb">
                            </div>
                          </td>
                        </tr>
                        <tr class="x1ay">
                          <td class="x1aa">
                            <div class="x1az">
                            </div>
                          </td>
                          <td colspan="3">
                            <div class="x1b0">
                            </div>
                          </td>
                        </tr>
                        <tr id="pt1:USma:0:MAt1:0:pt1:r1:0:AP1:r8:0:AT1:_ATp:ATexm" _afrdth="2" _afrgrp="1" class="x1a2 x1ab" onclick="return false;" tabindex="0" title="Export to Excel">
                          <td class="x1ae">
                            <div class="x1bb">
                            </div>
                          </td>
                          <td class="x1af">Export to Excel</td>
                          <td class="x1ag">
                            <div class="x1bb">
                            </div>
                          </td>
                          <td class="x1ah">
                            <div class="x1bb">
                            </div>
                          </td>
                        </tr>
                        <tr class="x1ay">
                          <td class="x1aa">
                            <div class="x1az">
                            </div>
                          </td>
                          <td colspan="3">
                            <div class="x1b0">
                            </div>
                          </td>
                        </tr>
                        <tr id="pt1:USma:0:MAt1:0:pt1:r1:0:AP1:r8:0:AT1:_ATp:cmi1" _afrdth="2" _afrgrp="2" class="x1a2 x1ab p_AFDisabled" onclick="return false;">
                          <td class="x1ae">
                            <div class="x1bb">
                            </div>
                          </td>
                          <td class="x1af">View Administrative Contacts</td>
                          <td class="x1ag">
                            <div class="x1bb">
                            </div>
                          </td>
                          <td class="x1ah">
                            <div class="x1bb">
                            </div>
                          </td>
                        </tr>
                      </table>
                    </div>
                  </td>
                </tr>
                <tr>
                  <td id="pt1:USma:0:MAt1:0:pt1:r1:0:AP1:r8:0:AT1:_ATp:ATm::sDwnBg" class="x26y">
                    <div id="pt1:USma:0:MAt1:0:pt1:r1:0:AP1:r8:0:AT1:_ATp:ATm::ScrollDown" class="x1a9" style="display: none">
                      <span class="x1aa"></span>
                    </div>
                  </td>
                </tr>
              </table>
            </div>
          </td>
          <td class="x19v">&nbsp;</td>
        </tr>
        <tr>
          <td id="pt1:USma:0:MAt1:0:pt1:r1:0:AP1:r8:0:AT1:_ATp:_vw::sDwnBg" class="x26y">
            <div id="pt1:USma:0:MAt1:0:pt1:r1:0:AP1:r8:0:AT1:_ATp:_vw::ScrollDown" class="x1a9" style="display: none">
              <span class="x1aa"></span>
            </div>
          </td>
        </tr>
      </table>
    </div>
  </div>
&#13;
&#13;
&#13;

我也尝试了框架,但没有成功。

有人可以帮助我捕获托管IE浏览器中点击的元素吗?

我无法更改页面的HTML代码,因为它不是我们的。

由于

1 个答案:

答案 0 :(得分:0)

如何获取点击的元素:

Dim oSrcEl As MSHTML.HTMLUnknownElement
Set oSrcEl = doc.parentWindow.event.srcElement

如果你想获得父元素的属性(也许你想获得父 tr 元素,因为它有 id ):

Dim oDomAttr As MSHTML.IHTMLDOMAttribute
Set oDomAttr = Nothing
Do
  Set oDomAttr = oSrcEl.Attributes.getNamedItem("id") 'attribute what i'm searching for
  Set oSrcEl = oSrcEl.parentElement 'parent element
'either I have found element with id attribute 
'or I'm at the top without success
Loop While oDomAttr Is Nothing And (Not oSrcEl Is Nothing)