vba - 如何使用 Selenium 单击 HREF
问题描述
尝试使用 Selenium 类型库在 Chrome 上单击下载按钮。下面的代码是我从板上拾取的代码,但我收到了语法错误
Sub Test()
Dim bot
Set bot = CreateObject("Selenium.WebDriver")
bot.Start "Chrome", "https://www.afterpaytouch.com"
bot.get "/results-reports"
bot.findElement(By.linkText("https://www.afterpaytouch.com/images/28082019-FY2019-Results-Presentation.pdf")).click()
End Sub
解决方案
我将在 VBE > Tools > References 添加对 Selenium 类型库的引用,然后使用早期绑定引用、完整 url 并应用 VBA selenium 基本语法通过 css 查找链接并单击
Option Explicit
Public Sub Test()
Dim bot As WebDriver
Set bot = New ChromeDriver
With bot
.Start "Chrome"
.get "https://www.afterpaytouch.com/results-reports"
.FindElementByCss("[href='https://www.afterpaytouch.com/images/28082019-FY2019-Results-Presentation.pdf']").Click
Stop '<delete me later
End With
End Sub
推荐阅读
- pyspark - pyspark:按ID计算连续差
- php - Laravel 观察者未触发
- javascript - Firebase 函数:类型错误:无法读取未定义的属性“user_id”
- objective-c - 使用 NSError 参数在 swfit 中实现 Objective-C 协议
- c - (ubuntu) ASLR - 清除混乱,奇怪的结果
- java - `assert` 是关键字,用 Gradle 编译
- bash - 计算不同列的时间差 - bash
- php - 从查询中获取所有月份,包括零计数
- python-3.x - 无法在数字海洋水滴上使用 python 脚本发送电子邮件
- reactjs - 如何在 React 无状态组件中编写和访问函数