excel - 通过 Excel VBA 单击 Internet Explorer 上的按钮
问题描述
我正在尝试通过 Excel 单击按钮。
重点是工作。但点击没有。
Set objCollection = IE.document.getElementsByTagName("button")
While i < objCollection.Length
If objCollection(i).Type = "submit" And objCollection(i).innerText = "Add items" Then
Set objElement = objCollection(i)
objElement.Focus
objElement.Click
End If
i = i + 1
Wend
解决方案
我做了一个快速测试:
' Add references to the project:
' « Microsoft Internet Controls » and « Microsoft HTML Object Library »
Sub Test()
Dim ie, button As Object
Dim ht As HTMLDocument
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate ("https://www.sampleforms.com/")
Do Until ie.readyState = 4
DoEvents
Loop
Set ht = ie.document
ie.document.querySelector("#searchVal").Value = "yaya"
Set button = ie.document.querySelector(".search-btn")
button.Click
Do Until ie.readyState = 4
DoEvents
Loop
End Sub
所以尝试:
Set button = ie.document.querySelector("#catalog.items.add")
推荐阅读
- git - GitLab - 远程:HTTP Basic:访问被拒绝 - 使用 Windows Git 客户端
- javascript - 从字符串的末尾到破折号获取一个数字
- python - 在 Python 中调用延迟评估时进行评估
- r - 如何仅在R中提取第一个数字字符之前的所有文本
- java - 如何从 Java 调用在 Scala 包对象上定义的案例类?
- r - 如果第二个数据帧中的条目的值在 R 中的前 50% 中,则用另一个数据帧中的一列覆盖一个数据帧中的一列
- sql - 获取 2 个最近事件的 SQL 窗口函数
- amazon-s3 - Angular Service Worker 和 CloudFront
- django - 使用 UUID 作为主键向 django 1.11 添加自动增量模型
- c# - 在 CEF 中设置 cookie 的路径?