gpt4 book ai didi

excel - 如何在 VBA 中单击

转载 作者:行者123 更新时间:2023-12-04 22:27:14 25 4
gpt4 key购买 nike

我需要帮助单击一个按钮,然后使用 VBA 在网页上选择选项。

网页链接:https://clinicaltrials.gov/ct2/results?cond=&term=Medpace&cntry=&state=&city=&dist=

我需要点击“显示/隐藏列”,然后选择“学习类型”、“阶段”、“赞助商/合作者”、“注册人数”、“NCT 号码”、“学习开始”、“学习完成”和“最后更新”发布”。

“显示/隐藏列”按钮的类:.getElementsByClassName("dt-button buttons-collection buttons-colvis").click

Private Sub Workbook_Open()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.application")
With IE
.Visible = True
.Navigate ("https://clinicaltrials.gov/ct2/results?cond=&term=Medpace&cntry=&state=&city=&dist=")
While .Busy Or .readyState <> 4: DoEvents: Wend

With IE.document
IE.Refresh
.getElementsByClassName("dt-button buttons-collection buttons-colvis").click
.querySelector("#save-list-link").click
.querySelector("#number-of-studies option:last-child").Selected = True
' .querySelector("#which-format option:fourth-child").Selected = True
' .querySelector("#which-format").selectedIndex = 3
' .querySelector ("#number-of-studies").selectedIndex = 1
' .querySelector("[value=csv]").click
.querySelector("#submit-download-list").click

' Set div = IE.document.getElementById("save-list-link")
' div.FireEvent "onclick"
End With
Application.Wait Now + TimeSerial(0, 0, 10)
Application.SendKeys "%+s", True
Application.Wait Now + TimeSerial(0, 0, 10)
.Quit

' For Each elt In IE.document.getElementById("number-of-studies")
' If InStr(elt.innerText, "Found") > 0 Then elt.click: Exit For
' Next elt

' Set div4 = IE.document.getElementById("submit-download-list")
' div4.click
End With
End Sub

最佳答案

在数组中添加其他所需的选项,然后循环所有按钮,检查按钮的 innerText 是否在数组中。如果是,则设置类名,以便按钮处于事件状态

Option Explicit
Public Sub MakeSelections()
Dim ie As Object, options()
options = Array("Study Type", "Phase", "Sponsor/Collaborators", "Number Enrolled", "NCT Number", "Study Start", "Study Completion", "Last Update Posted")
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
.Navigate2 "https://clinicaltrials.gov/ct2/results?cond=&term=Medpace&cntry=&state=&city=&dist="

While .Busy Or .readyState < 4: DoEvents: Wend

With .document
.querySelector(".buttons-collection").Click 'show/hide
Dim buttons As Object, i As Long
Set buttons = .querySelectorAll(".two-column button")
For i = 0 To buttons.Length - 1
If Not IsError(Application.Match(Trim$(buttons.item(i).innerText), options, 0)) Then
buttons.item(i).className = "dt-button buttons-columnVisibility active"
End If
Next
End With
Stop
.Quit
End With
End Sub

关于excel - 如何在 VBA 中单击 <button>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56674921/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com