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.sstatic.net/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
3
  • 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 Commented May 18, 2021 at 18:32
  • I like using Selenium for navigating websites and I had a similar question once (stackoverflow.com/questions/61625842/…). 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. Commented May 18, 2021 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. Commented May 20, 2021 at 18:05

0

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.