excel - 使用 VBA 单击按钮元素
问题描述
我相信我已经很接近了,但正在努力寻找并点击本网站上的正确元素。我已经让 VBA 为我登录并移动页面,但这个现在让我难过。我在用
以下是我检查要单击的按钮时的 HTML 选择:
[1]:https://i.stack.imgur.com/HIWEP.png
我一直在尝试使用一些方法,但我觉得我应该能够使用以下方法来获得它(我有一条评论指出应该在哪里):
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
解决方案
推荐阅读
- kubernetes - GKE Kubernetes RBAC 将默认角色绑定到我的有限自定义
- python-3.x - 浮点算术 - 指数的位
- javascript - 检查两个数组中有多少个变量是相同的
- android - Android Java:将 SQLite 导出为 CSV - 没有文件夹路径或文件创建问题
- python - 在 OTree 中实现自动转发到下一页
- agda - with语句中相等性证明的困难模式匹配
- assembly - 在汇编中保存 var 字节中的值
- python - 为什么在我完全不更改文件的情况下,训练时 tensorflow 会给我完全不同的结果?
- java - 如何使用 try/catch 验证用户输入并将结果传递给构造函数?
- winapi - 为什么在 WIN32 项目中需要 MyRegisterClass() 函数?