1

I'm new in VBA and i'm trying to automate a web Explorer navigation but with many difficolties. I've composed a script that navigate into a web page and search for a code. the result is a table ("dr-table-cell rich-table-cell") with one row that contains the searched item ("02090000062571") displayed as a link to another page. Here the code of that table:

<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>

My problem is to click on "02090000062571" href button (is the searched item) and execute the javascript fuction that diplayed another table.

Here my code:

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 

End Sub

I can find the item but I can't execute the code in order to press the button. I'm using IE 11.

Thanks for your patience!.

4
  • 1
    ie.Document.getElementById("formRicercaPdr:pdrTable:0:j_id134").getElementsByTagName("a")(0).Click Commented Jan 8, 2017 at 0:14
  • YOU ARE AWESOME!!! please can you tell me where I can find a complete documentation on DOM and HTML fro beginners. thanks Commented Jan 8, 2017 at 0:26
  • Most HTML DOM-related docs are based around using Javascript, but can typically be adapted to VBA without too much trouble. Maybe start here: developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/… Commented Jan 8, 2017 at 1:23
  • @TimWilliams, you should make this an answer, I will vote on it and it should help someone else in the future for sure. Commented Jan 8, 2017 at 1:30

1 Answer 1

1

This should work:

ie.Document.getElementById("formRicercaPdr:pdrTable:0:j_id13‌​4"). _
     getElementsByTag‌​Name("a")(0).Click  
Sign up to request clarification or add additional context in comments.

1 Comment

hi tim Sory if a contact you in this way but I'm stack with a button inside an iframe. I'd be happy if you can look just few minutes on that problem. The post is "How to click a button inside IFrame vba" thanks in advance

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.