获取div VBA中的元素

时间:2016-06-06 20:43:25

标签: html vba

我有以下HTML:

 <div id="div_2_1_3" class="Button  CoachView CoachView_show" 
   data-type="com.ibm.bpm.coach.Snapshot_5b0cf92e_d5be_41c3_b0d3_f101b717826c.Button"
  data-binding="" data-bindingtype="" data-config="config3" 
   data-viewid="Button3" data-eventid="boundaryEvent_4">

      <button type="button" class="BPMButton BPMButtonBorder"

我必须单击按钮,该类是BPMButton BPMButtonBorder。

我正在尝试此代码,但是返回错误:运行时错误:&#39; 438&#39;:对象不支持此属性或方法。 如何点击BPMButton BPMButtonBorder?

sub html

Set divs = ie.getElementBytagname("div")
For Each divi In divs   
    If divi.id = "div_2_1_3" Then Set botoes = ie.Document.getElementsByTagName("BUTTON")
       For Each bt In botoes
            If bt.ClassName = "BPMButton BPMButtonBorder" Then
                bt.Click
                Exit For
            End If
        Next bt
Next divi
end sub

2 个答案:

答案 0 :(得分:1)

尝试这样的事情:

Sub html
    Dim div, botoes, bt

    'edit - added missing .document
    Set div = ie.document.getElementById("div_2_1_3")
    Set botoes = div.getElementsByTagName("BUTTON")

    For Each bt In botoes
       Debug.Print bt.ClassName
       If bt.ClassName = "BPMButton BPMButtonBorder" Then
           bt.Click
           Exit For
       End If
    Next bt

end sub

答案 1 :(得分:0)

蒂姆,我相信在之后缺少文件。 它适用于此代码:

Set botoes = ie.Document.getElementsByTagName("button")
    For Each bt In botoes
Debug.Print bt.innertext
    If bt.innertext = "Run Now" Then
       bt.Click
   Exit For
End If
Next bt