我已成功通过Internet Explorer中的Excel VBA下拉菜单,但我无法点击第二个孩子DIV
。虽然我可以debug.print
下拉列表中的内容,但我无法在fireevent
内设置DIV
。这是我正在处理的源代码以及我到目前为止所做的事情。
<div style="border-width: 1px; z-index: 1018; visibility: visible; height: 238px; width: 304px; left: 1566px; top: 144px;" role="presentation" id="x-auto-1048" class="x-combo-list x-ignore x-component x-border "><div tabindex="0" hidefocus="true" id="x-auto-318" class=" x-view x-combo-list-inner x-component x-unselectable" style="overflow-x: hidden; padding: 0px; border-width: 0px; height: 238px; width: 304px;" unselectable="on"> <div class="x-combo-list-item x-panel-header "> Actions</div><div class="x-combo-list-item ">Add Lead Disposition</div><div class="x-combo-list-item x-view-highlightrow x-combo-selected">Add Lead Assignment Priority</div><div class="x-combo-list-item x-panel-header ">Audits</div><div class="x-combo-list-item ">Account Settings</div><div class="x-combo-list-item x-panel-header ">Actions</div><div class="x-combo-list-item ">Add Lead Disposition</div><div class="x-combo-list-item ">Add Lead Assignment Priority</div><div class="x-combo-list-item x-panel-header ">Audits</div><div class="x-combo-list-item ">Account Settings</div></div></div>
这就是我到现在为止所做的事情
Private Sub CommandButton2_Click()
Dim ie As Object
Dim button As Variant
Dim var As String: var = ActiveCell.Value
Dim disp As Object
Dim dis As Object
Dim innnerr As Variant
Dim i As Long: i = 0
ReDim innnerr(1000)
Set ie = CreateObject("internetexplorer.application")
ie.Visible = True
With ie
.Visible = True
.navigate "http://controlpanel.sukutrade.verio/index.html#account-overview?sukuAccountUsername=" & var
While .readyState = READYSTATE_COMPLETE
Wend
End With
'Wait some to time for loading the page
While ie.Busy
DoEvents
Wend
Application.Wait (Now + TimeValue("0:00:02"))
ie.document.getElementById("x-auto-317-input").Click
Set disp = ie.document.getElementById("x-auto-1048").getElementsByTagName("div")
For Each dis In disp
innnerr(i) = dis.innerText
If dis.innerText = "Add Lead Disposition" Then dis.fireevent "onclick"
i = i + 1: Exit For
Next dis
Application.Wait (Now + TimeValue("0:00:02"))
ie.Quit
End Sub
我需要的是点击具有innertext&#34; Add Lead Disposition&#34;的第二个孩子。
编辑:根据我得到的答案,迭代工作正常,但Click
事件未触发。我在没有解决方案的情况下使用.Focus
尝试了Onclick
和FireEvent
。任何帮助表示赞赏。
答案 0 :(得分:1)
Dim post As Object
For Each post In IE.document.getElementsByClassName("x-combo-list-item")
If InStr(post.innerText, "Add Lead Disposition") > 0 Then post.Click: Exit For
Next post