0

I believe I am close but am struggling finding and clicking the correct element on this website. I have gotten VBA to log in and move pages for me but this one is stumping me now. I am using

Below is the HTML selection when I inspect the button I want to click on:

[1]: https://i.stack.imgur.com/HIWEP.png

I have been attempting using a few methods but I feel like I should be able to get it using something like the following (I have a comment pointing out where this should be):

Sub Login()

    Const Url$ = "examplewebsite.com"

    Dim HTMLDoc As HTMLDocument
    Dim oHTML_Element As IHTMLElement


    Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")

    With ie

        .Navigate Url
        .Visible = True
    
        Do While ie.Busy Or ie.ReadyState < 4
            DoEvents
        Loop
  
    
        Set HTMLDoc = ie.Document
        
        
        Dim Login As Object
        Dim Password As Object
        Dim LoginButton As Object
    
        For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
            If oHTML_Element.Name Like "txt_1*" Then Set Login = oHTML_Element
            If oHTML_Element.Name Like "txt_2*" Then Set Password = oHTML_Element
            If oHTML_Element.Name Like "btnLogin*" Then Set LoginButton = oHTML_Element
        Next



        Login.Value = ""
        Password.Value = ""
    
        LoginButton.Click
    
    
        Do While ie.Busy Or ie.ReadyState < 4
        DoEvents
        Loop
        
        Call HTMLDoc.parentWindow.execScript("LoadContent('Report1017','ReportsList/ReportList.aspx?ReportParam=1017')", "JavaScript")
       
       
       Do While ie.Busy Or ie.ReadyState < 4
        DoEvents
        Loop
        
       'This is where I am stumped but think something like this should work:
       HTMLDoc.getElementById("dlReportList_ctl00_hdnReportId").Click
        
        
         
    End With

End Sub
K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43
MrNelson
  • 5
  • 1
  • That didn't work however would I be able to directly grab the href link? I have been doing some google searches and am wondering if a query selector would work. Below is what I've been trying but it is not working: HTMLDoc.querySelector("a[href^='ReportsList/ReportViewer.aspx?ParentFolderId=1017&ReportPath=/COMED/Comed Reports/&ParentId=1017&IsSubReport=False&SSRSName=All Projects Report&ReportName=All Projects Report']").Click – MrNelson May 18 '21 at 18:32
  • I like using Selenium for navigating websites and I had a similar question once (https://stackoverflow.com/questions/61625842/how-to-click-a-webpage-button-in-vba-for-parsing). Using xpath can also help you narrow down on the element you are trying to click on. If you provide the website I can try looking into it. – Christopher Weckesser May 18 '21 at 21:46
  • Unfortunately, I can not provide you the website as it is for my company and will require credentials anyway. I will do some testing using the methods you described. – MrNelson May 20 '21 at 18:05

0 Answers0