0

Trying to work on a Macro to login into a website and then download some data. Currently I am having trouble getting it to click on a link in the site.

Code:

Sub GetHTLMDocuments()

    Dim IE As New SHDocVw.InternetExplorerMedium
    Dim HTMLDoc As MSHTML.HTMLDocument
    Dim HTMLInput As MSHTML.IHTMLElement
    Dim HTMLButtons As MSHTML.IHTMLElementCollection
    Dim HTMLButton As MSHTML.IHTMLElement

    IE.Visible = True
    IE.navigate "xxx.yyy"

    Do While IE.readyState <> READYSTATE_COMPLETE
        Application.Wait Now + TimeValue("00:00:03")
        DoEvents
    Loop
    
    Application.Wait Now + TimeValue("00:00:02")
    
    ShowWindow IE.hwnd, SW_MAXIMIZE

    Set HTMLDoc = IE.document
    
    Application.Wait Now + TimeValue("00:00:02")
    
    Set ElementCol = IE.document.getElementById("periods")
      For Each btnInput In ElementCol
          If btnInput.Value = "selected" Then
              btnInput.Click
              Exit For
          End If
      Next btnInput

    IE.Quit

End Sub

Here's the html code from the site:

enter image description here

I would like to change the class which state the selected (or unselected) of the "option" element, any idea?

also tried to print all the Elements by class name......


Debug.Print InStr(1, HTMLDoc.body.outerHTML, "periods", vbTextCompare)

Dim dd As Variant

dd = IE.document.getElementsByClassName("periods")(0).innerText

IE.document.querySelector("[title='periods']").Click

    For Each link In IE.document.getElementsByTagName("*")

        With link
            If .innerText = "periods" Then
            link.Click
            End If
        End With

    Next
  • 1
    In the HTML shown, there is neither a button nor a link. There is also no ID with the value `periods`. There is only `data-action-link-id="periods"`. This is a simple attribute that can occur any number of times. Apart from that, IE should not be used anymore, because since June 2022 it is not supported at all. Does the page still work when you call it manually in IE or is it called in the Edge browser? Is the URL secret? Is the page on the Internet or on an intranet? – Zwenn Oct 31 '22 at 18:12
  • @Zwenn, thank you for the clarification with regard the HTML structure (I am not an expert), for the rest of the questions, it is an intranet page and yes it is still working in IE! I have already checked and the “data-action-link-id” with the “periods” attribute shows only once in the page, is there a way to trigger them? – Coccolillo Oct 31 '22 at 18:42
  • I'm pretty sure there are events stored for the entries you're concerned with. The right one has to be triggered for the desired HTML element. Have a look at the following solution to understand the topic first. You have more pitfalls in front of you I guess. But first have a look here: https://stackoverflow.com/questions/63294113/automate-ie-via-excel-to-fill-in-a-dropdown-and-continue/63299608#63299608 – Zwenn Oct 31 '22 at 21:30

0 Answers0