Vba 如何使用Selenium单击HREF

Vba 如何使用Selenium单击HREF,vba,selenium-webdriver,web-scraping,Vba,Selenium Webdriver,Web Scraping,尝试使用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.afterpa

尝试使用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
选项显式
公共子测试()
Dim bot作为Web驱动程序
设置bot=新的色度驱动器
用机器人
.启动“Chrome”
.得到“https://www.afterpaytouch.com/results-reports"
.FindElementByCss(“[href=”https://www.afterpaytouch.com/images/28082019-FY2019-Results-Presentation.pdf“]”。单击

停止“您可能希望将
bot
变暗为一个“对象”,而不是假定的
变体,但这可能无法解决问题。请解释你在哪一行上出错。你忘了在问题中包含这一点。错误出现在bot.FindElement行上-我可以很好地打开网页,但无法单击下载按钮,而不是尝试在一行中全部单击,首先将元素设置为变量,然后检查变量是否先设置为某个值。如果没有,则无法找到该元素。我的最佳猜测是,您不希望包含元素的整个路径。-请同时发布语法错误。尝试将元素设置为变量,但我收到一个“Sub或Function not defined error”````Sub Test()Dim bot set bot=CreateObject(“Selenium.WebDriver”)Dim element set element=FindElement(By.linkText(“))