2017-01-08 52 views
1

我是VBA新手,我試圖自動化一個Web Explorer導航,但有許多難點。 我編寫了一個導航到網頁並搜索代碼的腳本。結果是一個表格(「dr-table-cell rich-table-cell」),其中一行包含顯示爲另一頁面鏈接的搜索項目(「02090000062571」)。這裏該表的代碼:VBA onclick事件Internet Explorer無法正常工作

<td class="dr-table-cell rich-table-cell" 
    id="formRicercaPdr:pdrTable:0:j_id134"> 
    <a onclick="if(typeof jsfcljs == 'function'){jsfcljs(document.forms['formRicercaPdr'],'formRicercaPdr:pdrTable:0:j_id136,formRicercaPdr:pdrTable:0:j_id136','');}return false" 
     href="#">02090000062571</a> 
</td> 

我的問題是點擊「02090000062571」 HREF按鈕(是搜索的項目)並執行diplayed另一個表的JavaScript機能的研究。

這裏我的代碼:

Sub TriggerDivClick() 
Dim ie As SHDocVw.InternetExplorer 
Dim doc As MSHTML.HTMLDocument 
Dim div As HTMLDivElement 
Dim url As String 

url = "some URL" 

Set ie = New SHDocVw.InternetExplorer 

ie.Visible = True 
ie.Navigate url 

While ie.Busy Or ie.ReadyState <> READYSTATE_COMPLETE 
    DoEvents 
Wend 
Set pdr_button = ie.Document.getElementsByClassName("dr-table-cell rich-table-cell") 
For Each a In pdr_button 
'here comes the problems 

a.Item(0).FireEvent ("click()") 

Next a 

末次

我能找到這個項目,但我不能爲了按下按鈕執行代碼。 我使用IE 11.

感謝您的耐心配合!

+1

'ie.Document.getElementById( 「formRicercaPdr:pdrTable:0:j_id134」)的getElementsByTagName( 「A」)(0).Click' –

+0

YOU ARE真棒!。 !請告訴我在哪裏可以找到DOM和HTML初學者的完整文檔。謝謝 – Roberto

+0

大多數與HTML DOM相關的文檔都基於使用Javascript,但通常可以適應VBA而不會有太多麻煩。也許從這裏開始:https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction –

回答

0

這應該工作:

ie.Document.getElementById("formRicercaPdr:pdrTable:0:j_id13‌​4"). _ 
    getElementsByTag‌​Name("a")(0).Click 
+0

嗨蒂姆Sory如果以這種方式聯繫你,但我與一個iframe中的按鈕堆棧。如果你能在這個問題上看幾分鐘,我會很高興。這篇文章是「如何點擊IFrame vba中的按鈕」,這要提前感謝 – Roberto

相關問題