vba - 在 VBA 中使用硒打印网页
问题描述
我正在尝试在 VBA 中使用硒打印网页。我希望机器人能够按 control+P,然后在打印对话框上按 Enter,但不断收到 object required 错误。有人有想法么?
Sub printing()
Dim bot As New WebDriver, controlP As Variant, enter As Variant
bot.Start "chrome", ""
bot.Get "https://www.google.com/"
controlP = (Keys.Control & "p")
enter = (Keys.enter)
bot.FindElementByXPath("/html").SendKeys (conrolP)
bot.FindElementByXPath("/html").SendKeys (enter)
End sub
解决方案
我不确定您尝试的方法是实现目标的方法。但是,这里有几点:
- 我认为相关的 xpath 应该是
//html
. - 使用Option Explicit作为模块代码的第一行;你有一个错字,
conrolP
它Option Explicit
会提醒你作为一个未声明的变量。 - 你也不需要那些
()
带有SendKeys
.
推荐阅读
- html - Workbox - Service Worker 从缓存中提供的文件,即使使用的缓存策略是 NetworkOnly
- snowflake-schema - 雪花:复制命令在卸载时不会为多个文件生成恒定大小
- .net-core - 核心 3.1:无法在 .DLL 项目中运行 dotnet ef 迁移(找不到框架)
- ios - 为什么在动画期间引用 CALayer 父视图的属性为“nil”
- javascript - For循环使用带有传递参数的函数调用的长度,什么属性提供长度值?
- java - 如何在 Spring JAVA(JPA/Hibernate)中映射 MySQL 时间戳字段
- azure - 如何通过服务总线消息触发 Azure 函数并将消息输出到单个 Azure 函数中的服务总线
- python - InvalidSchema("No connection adapters were found for {!r}".format(url)) 在使用 ConfigParser 解析的请求模块上的 URL 时
- android - 如何在 xml 中设置 RecyclerView 的最大高度?
- ios - 如何在 Swift 中舍入 UITextField 的 topRight 和 bottomLeft 角