Click HTML Dropdown with VBA

Caleeco

Well-known Member
Joined
Jan 9, 2016
Messages
980
Office Version
  1. 2010
Platform
  1. Windows
Hello,

I'm trying to develop a spreadsheet that will load webpage and interact with it. I have been able to load the website, login and click some buttons.

However I can't seem to click the "Enter Time" from the "Action" dropdown using the same method.

I have attached the InspectElement code & the VBA snippet below.

Can anyone advise how to do this?

Many Thanks
Caleeco

VBA Code:
Sub Uploader()

'-- Create instance for IE Object & Navigate to Website
    IE.Visible = True
    IE.navigate "https://somewebsite.com"
    Do While IE.Busy = True Or IE.readyState <> 4: DoEvents: Loop           'Wait until page has loaded
    Set HTMLDoc = IE.document
    
'-- Loop button tags and click Actions Dropdown
    Call Click_HTML_Element("button", "Actions", "2")  'This Works
    Call Click_HTML_Element("div", "Enter Time", "1")  'This doesnt work
'    Application.SendKeys "{DOWN}"
'    Application.SendKeys "{Enter}"
    
End Sub


Function Click_HTML_Element(Element As String, Tag As String, WaitTime As String)
  
    Set HTMLButtons = HTMLDoc.getElementsByTagName(Element)
    Application.Wait (Now + TimeValue("00:00:0" & WaitTime))
    Do While IE.Busy = True Or IE.readyState <> 4: DoEvents: Loop
    For Each ButtonTag In HTMLButtons
        If Left(ButtonTag.innerText, Len(Tag)) = Tag Then
            ButtonTag.Click
            Exit For
        End If
    Next ButtonTag

End Function
 

Attachments

  • MrX_EnterTime.JPG
    MrX_EnterTime.JPG
    70.4 KB · Views: 16

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Managed to figure out a solution. I just referenced the absolute ID using the line below

VBA Code:
IE.document.getElementById("377b4ac57a2e4397aa16df36599c4c17").Click

Although, im not sure if this stays consistent? o_O

Cheers
Caleeco
 
Upvote 0

Forum statistics

Threads
1,214,967
Messages
6,122,503
Members
449,090
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top