html - VBA点击按钮
问题描述
使用 VBA 的 Internet Explorer 按钮出现问题。
我需要有关使用 vba 单击按钮的帮助。问题是当我自动输入用户名和密码时按钮不可点击。只有当我手动输入用户名和密码时它才可点击。我的代码可与网站上的其他按钮一起使用,但此按钮除外。
'这是我的代码中输入用户名、密码并点击按钮的部分。
Set HTMLInput = HTMLDoc.getElementById("USER")
HTMLInput.Value = "user"
Set HTMLInput = HTMLDoc.getElementById("Password")
HTMLInput.Value = "password"
Set HTMLButton= HTMLDoc.getElementById("subBtn")
HTMLButton.Click
'这是按钮信息
<button type="submit" class="btn btn-primary ng-scope" data-ng-click="saveUserID()" id="subBtn" translate="signin.signin">Sign In</button>
我在某处读过,我可以使用它Application.sendkeys"username",True
来模拟键盘上的打字,看看按钮是否可以点击,但我也无法让它工作。还有其他方法可以使此按钮可点击吗?
解决方案
尝试让网站认为您输入的是真实的这些值。例如:
Set HTMLInput = HTMLDoc.getElementById("USER")
HTMLInput.Focus '<-- set the focus on the input (make the element the active one)
Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 1) '<-- wait a second
HTMLInput.Value = "user"
Set HTMLInput = HTMLDoc.getElementById("Password")
HTMLInput.Focus '<-- set the focus on the input (make the element the active one)
Application.Wait TimeSerial(Hour(Now()), Minute(Now()), Second(Now()) + 1) '<-- wait a second
HTMLInput.Value = "password"
Set HTMLButton= HTMLDoc.getElementById("subBtn")
HTMLButton.Click '<-- finally click the button
注意:由于您没有共享 URL,因此此代码未经测试。但它过去在某些基于 JavaScript 的网站上对我有用。
推荐阅读
- javascript - 在 JavaScript 中按数组属性分组
- rest - 授权 REST 资源访问
- php - 如何将 php 文件相互交错并检查参数的 URL?
- c++ - C++ 客户端/服务器聊天应用程序 - 从 Ubuntu 命令窗口扫描输入
- mongodb - 仅将更改的值从表单提交更新到 MongoDB
- azure - Azure Devops 项目——它们来自哪里?如何去除?
- methods - V-for循环方法不直接导致渲染
- php - PHP将数字增加到10位数字10000次得到不准确的结果
- javascript - 从定义的数值生成行并将公式应用于工作表
- python - python google calendar api'NoneType'对象没有属性'authorize'