jeudi 4 juin 2020

Clicking on a dropdown menu option in Internet Explorer

I'm an amateur when it comes to coding, but I am just trying to make a simple VBA script to pull some invoices for my job. I can get VBA to open the webpage that I am at, but I can't get it to open the dropdown menu I need and click on the link I need it to click on. The HTML is:

<div class="fnBtnContainerDIV" style="left: 146px; top: 4px; position: absolute; z-index: 9998;">
    <div class="secondary-btn"><a href="#">Functions</a></div>
    <span style="float: left;">&nbsp;</span>
    <div class="secondary-dropdown" style="left: 95.14px; top: 19px; width: 195px; display: none; position: absolute; z-index: 9998;">
        <ul>
            <li><a name="YsiLinkList1:LinkList:DataTable:row0:Value:anchor" tabindex="-1" id="YsiLinkList1:LinkList:DataTable:row0:Value_anchor"
                   href="javascript:OpenNewWindow('/34478dra/Pages/SysAttachmentView.aspx?iType=30&amp;hRecord=300073209');">Attachment</a></li>
            <li><a name="YsiLinkList1:LinkList:DataTable:row1:Value:anchor" tabindex="-1" id="YsiLinkList1:LinkList:DataTable:row1:Value_anchor"
                   href="javascript:OpenNewWindow('/34478dra/Pages/../Pages/PayableTransCustom.aspx?hPayable=300073209');">Third-party Invoice Image</a></li>
            <li><a name="YsiLinkList1:LinkList:DataTable:row2:Value:anchor" tabindex="-1" id="YsiLinkList1:LinkList:DataTable:row2:Value_anchor"
                   href="javascript:OpenNewWindow('../pages/PSDetail.aspx?ObjectType=30&amp;RecordId=300073209');">Audit History</a></li>
        </ul>
    </div>
</div>

Screenshot of the HTML

Sorry if that didn't format correctly. The link has a photo of what the HTML looks like. I've tried a bunch of different things, but I just don't understand how to interact with HTML at all. Here's my latest attempt:

Sub GetInvoices()
Dim IE As Object
Dim aEle As HTMLLinkElement
Dim y As Integer
Dim result As String
Dim URL As String

Set IE = CreateObject("InternetExplorer.Application")
URL = Range("Q558").Value

IE.Visible = True
IE.Navigate URL
Do While IE.Busy = True Or IE.ReadyState <> 4: DoEvents: Loop

Set AvailabeLinks = IE.Document.getElementsByTagName("a")
For Each cLink In AvailableLinks
    If cLink.innerHTML = "Third-party Invoice Image" Then
        cLink.Click
    End If
Next cLink
End Sub

I keep getting a type mismatch error on the For loop. I'd appreciate any help I can get. I'm just trying to learn. Thanks




Aucun commentaire:

Enregistrer un commentaire