excel - Excel VBA单击html div类中的项目
问题描述
我是第一个使用 Excel VBA 进行 Web 自动化的新手。到目前为止,我能够取得进展,但在尝试点击网站上看起来像按钮的东西时遇到了困难。如果你能帮助我,请告诉我,我很感激。谢谢!特定元素位于以下 html 代码中的 a 标记内:
<div class="sh-c-btn-group">
<input name="pf.ok" type="hidden" value="">
<input name="pf.cancel" type="hidden" value="">
<a title="Sign In" class="sh-c-btn sh-c-btn--primary" onclick="postOk();">Sign In</a>
</div>
解决方案
Jenn 和 Jumpgroup,非常感谢您的帮助 :) 通过获取标题和类名,设法通过以下循环来做到这一点:
Dim HTMLas As MSHTML.IHTMLElementCollection
Dim HTMLa As MSHTML.IHTMLElement
Set HTMLas = HTMLDoc.getElementsByTagName("a")
For Each HTMLa In HTMLas
If HTMLa.getAttribute("title") = "Sign In" And HTMLa.getAttribute("classname") = "sh-c-btn sh-c-btn--primary" Then
HTMLa.Click
Exit For
End If
Next HTMLa
推荐阅读
- sass - PhpStorm - 在编译时禁用“.sass-cache”的生成(文件观察器)
- go - 泄漏的 goroutines,通常运行的数量是我想要的三倍
- asp.net-core - dotnet core 将测试项目排除在launchSettings.json中构建
- vue.js - 过滤前的Vuetify自动完成最小字符
- visual-studio-code - VSCode 中的 CSS/HTML 建议,如 WebStorm
- powershell - 添加内容:拒绝访问路径“C:\”
- python-3.x - 保存和加载 Pytorch 模型检查点以进行推理不起作用
- c# - efcore 2.2 在使用 LazyLoadedProxies 时关闭特定查询的代理创建
- swift - 无法将类型“IndexPath”的值分配给类型“Int”
- ios - React Native xcode 项目“标头搜索路径”