簡體   English   中英

如何使用vba自動檢查IE中RadComboBox下拉列表中的CheckBox

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

我正在使用vba自動完成網頁上的一些搜索參數。 我可以選擇/點擊正常的下拉列表和其中的元素,但這一個帶有復選框的下拉列表令人頭疼。

所以我得到了頁面,等待加載等我可以點擊一個下拉列表,我甚至可以點擊相關的下拉列表來顯示列表。 但是,當我想要選擇此特定列表中的一個框時,它就會停止。

我嘗試了很多東西,所以我不能一提。 但我懷疑如果你知道我是新手的HTML很容易。

不幸的是我無法提供該網站的鏈接,因為它是內部的,但我可以提供一些HTML。

所以下面是我點擊下拉列表並使用DOM資源管理器來識別復選框的地方:(是的,我已經用<和>替換了|來獲取html。對不起。)

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

| DIV class = rcbCheckAllItems jQuery11110353987455483101044 =“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 /中心詳細信息| / LABEL || / LI |

| LI class = rcbItem_itemTypeName =“Telerik.Web.UI.RadComboBoxItem”|| LABEL || INPUT class = rcbCheckBox CHECKED type = checkbox value =“”|子類別和族| / LABEL || / LI || / UL || / DIV || / DIV |

我的代碼(或其相關部分):

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.

請注意,我已經嘗試了“Doc.getElementsByClassName(”r​​cbCheckAllItemsCheckBox“)但得到運行時錯誤438,Object不支持此屬性或方法。

我希望SelectByInput.Checked = True可以密封交易,如果只能到元素class =“rcbCheckAllItemsCheckBox”(標簽“全部檢查”)或兩個其他(帶標簽“ERP /中心詳細信息”和“子類別和家庭”。

我的解決方案需要確保兩個結果中的任何一個是等價的。 1)選中頂部復選框(標簽“全部檢查”)2)檢查另外兩個復選框

謝謝。

請嘗試以下方法

ie.document.querySelector(".rcbCheckAllItemsCheckBox").click 'N.B. if already checked will uncheck

要么

ie.document.querySelector(".rcbCheckAllItemsCheckBox").checked = True

另一種方法是循環輸入控件並嘗試檢查類和其他屬性。 如果匹配,則選中復選框。

碼:

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

輸出:

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM