i'm wondering how can i manage to click on an html element through VBA if another condition is satisfied. To make it clear, i will show you a short example:
i need to analize data in a specific quarter ('let's say i need Q2) and for each quarter html elements are grouped in class=module_item in the same page (EXAMPLE) .
The website is https://investor.apple.com/investor-relations/default.aspx
My code is this:
Dim IE As New InternetExplorer
Dim iedoc As MSHTML.HTMLDocument
Dim element As MSHTML.IHTMLElement
Dim elements As MSHTML.IHTMLElementCollection
Dim quarter As MSHTML.IHTMLElement
Dim freport As MSHTML.IHTMLElement
With IE:
.navigate "https://investor.apple.com/investor-relations/default.aspx"
.Visible = True
End With
Do While IE.readyState <> READYSTATE_COMPLETE
Loop
Set iedoc = IE.document
Set elements = iedoc.getElementsByClassName("module_item")
Set quarter = iedoc.getElementsByClassName("module-financial_year-text")
Set freport = iedoc.getElementsByClassName("module_link module_link-statement")
For Each element In elements:
If quarter.innerText = "Q2" Then
freport.Click
End If
Debug.Print element.innerText
Next element
End Sub
Can you help me?