excelvbainternet-explorerradcombobox

How to automate checking a CheckBox in RadComboBox dropdown in IE using vba


I'm automating the completion of some search parameters on a web page using vba. I can get to the selection/clicking of normal dropdown lists and the elements within, but this one dropdown with checkboxes is creating some headache.

So I get the page, the wait to load etc. I can click a dropdown and I can even click the relevant dropdown to get the list displayed. However it's when I want to select one of the boxes in this particular list it stops.

I've tried lots of stuff so I can't mention it all. But I have a suspicion it is easy if you know HTML which I'm a novice at.

Unfortunately I can't provide a link to the site as it is internal, but I can provide some of the html.

So the below is where I get to when I've clicked the dropdown and uses the DOM Explorer to identify the checkbox:(yes I've replaced < and > with | to get the html in. Sorry about that.)

|DIV id=ctl00_MainContentPlaceHolder_RadComboBoxChooseColumns_DropDown class="RadComboBoxDropDown RadComboBoxDropDown_Web20 " style="WIDTH: 248px; FLOAT: left; DISPLAY: block; TOP: 0px; VISIBILITY: visible" jQuery1111035398745548310944="16"||DIV class="rcbScroll rcbWidth" style="HEIGHT: 78px" jQuery1111035398745548310944="9"

|DIV class=rcbCheckAllItems jQuery1111035398745548310944="18"||LABEL||INPUT class=rcbCheckAllItemsCheckBox CHECKED type=checkbox value=""|Check All|/LABEL||/DIV|

|UL class=rcbList style="LIST-STYLE-TYPE: none; ZOOM: 1; PADDING-BOTTOM: 0px; PADDING-TOP: 0px; PADDING-LEFT: 0px; MARGIN: 0px; PADDING-RIGHT: 0px" jQuery1111035398745548310944="14"|

|LI class=rcbHovered_itemTypeName="Telerik.Web.UI.RadComboBoxItem"||LABEL||INPUT class=rcbCheckBox CHECKED type=checkbox value=""|ERP/Center details|/LABEL||/LI|

|LI class=rcbItem_itemTypeName="Telerik.Web.UI.RadComboBoxItem"||LABEL||INPUT class=rcbCheckBox CHECKED type=checkbox value=""|Sub category and families|/LABEL||/LI||/UL||/DIV||/DIV|

My Code (Or relevant parts of it):

Dim ie As InternetExplorer
Set ie = New InternetExplorerMedium
Set Doc = CreateObject("htmlfile")
Set Doc = ie.document

Dim SelectByInput As Object
Set SelectByInput = Doc.getElementByID_
("ctl00_MainContentPlaceHolder_RadComboBoxChooseColumns_DropDown")
'This is OK. but miss part to get to the Checkbox.

Please note that I've tried "Doc.getElementsByClassName("rcbCheckAllItemsCheckBox") but get runtime error 438, Object doesn't support this property or method.

I would expect SelectByInput.Checked=True would seal the deal if could just get to the element class ="rcbCheckAllItemsCheckBox" (Label "Check All") or both the two others (with Labels "ERP/Center details" and "Sub category and families".

I solution need to ensure either of the two outcomes which are equivalent. 1) The top checkbox is checked (Label "Check All") 2) Both the two other checkboxes are checked

Thank you.


Solution

  • An alternative approach is to loop through input controls and try to check class and other properties. If it get match then checked the check box.

    Code:

    Public Declare Function SetForegroundWindow Lib "user32" (ByVal HWND As Long) As Long
    
    Sub demo()
        Dim i As Long
        Dim URL As String
        Dim IE As Object
        Dim objElement As Object
        Dim objCollection As Object
        Dim HWNDSrc As Long
    
        Set IE = CreateObject("InternetExplorer.Application")
    
        IE.Visible = True
    
        URL = "C:\Users\Administrator\Desktop\91.html"
    
        IE.navigate URL
    
        Do While IE.readyState = 4: DoEvents: Loop
        Do Until IE.readyState = 4: DoEvents: Loop
    
        HWNDSrc = IE.HWND
    
        SetForegroundWindow HWNDSrc
    
    
       Set ElementCol = IE.document.getElementsByTagName("input")
    
        For Each btnInput In ElementCol
    
           ' Debug.Print btnInput.className
            If btnInput.className = "rcbCheckAllItemsCheckBox" Then
                btnInput.Checked = True
            End If
        Next btnInput
    
        'Set IE = Nothing
       ' Set objElement = Nothing
       ' Set objCollection = Nothing
    
    End Sub
    

    Output:

    enter image description here