首页 > 解决方案 > 在 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

标签: vbaselenium-webdriverprintingbots

解决方案


我不确定您尝试的方法是实现目标的方法。但是,这里有几点:

  1. 我认为相关的 xpath 应该是//html.
  2. 使用Option Explicit作为模块代码的第一行;你有一个错字,conrolPOption Explicit会提醒你作为一个未声明的变量。
  3. 你也不需要那些()带有SendKeys.

推荐阅读