0
我想要做的是打開一個網站,然後按下按鈕。我不能讓它工作,所以我要求你們所有有經驗的程序員!IE頁面上的VBA點擊按鈕
按鈕XML記錄是:
z-menu-item-inner-r"><span class="z-menu-item-space"></span></td></tr></tbody></table></a></td><td id="z_e6_mm" align="left" z.type="Menuit2" class="z-menu-item " style="padding-left:4px;padding-right:4px;" z.zcls="z-menu-item" z.top="true"><a href="/NTS/NTSBatchJobs.zul" class="z-menu-item-cnt"><table id="z_e6_mm!a" cellspacing="0" cellpadding="0" border="0" class="z-menu-item-body " style="width: auto;"><tbody><tr><td class="z-menu-item-inner-l"><span class="z-menu-item-space"></span></td><td class="z-menu-item-inner-m"><div><button id="z_e6_mm!b" type="button" class="z-menu-item-btn">**HIT ME** </button></div></td><td class="
按鈕我試圖按被命名爲: HIT ME
我使用的代碼:
Sub IE_Auto()
Dim i As Long
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "mysite"
Set elems = IE.Document.getElementsByTagName("button")
For Each e In elems
If e.Name = "Hit Me" Then
e.Click
Exit For
End If
Next e
End Sub
謝謝您的快速響應。我得到運行時錯誤:自動化錯誤。接口是未知的,它停在設置btn = IE.Document.getElementById(「z_e6_mm!b」) – Golemic
需要IE8 +你有什麼版本?您可能還需要爲IE準備好/等待循環以允許頁面完成加載。同樣,從XML驗證正確的元素ID。 –
我的IE版本是8.0.7601.17514。我也添加了一個等待循環,持續10秒:Application.Wait DateAdd(「s」,10,Now)。我如何驗證這是正確的元素?我用按鈕標題搜索! – Golemic