【发布时间】:2019-11-29 23:25:59
【问题描述】:
尝试使用 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
【问题讨论】:
-
您可能希望将
bot调暗为`Object` 而不是假定的Variant,但这可能无法解决问题。请解释您在哪一行得到错误。你忘了在你的问题中包含这个。 -
错误出现在bot.FindElement行 - 我可以正常打开网页但无法点击下载按钮
-
与其尝试在一行中全部单击,不如先将元素设置为变量,然后检查变量是否首先设置为某个值。如果没有,则它无法找到该元素。我最好的猜测是您不想包含元素的整个路径。 - techbeamers.com/findelement-and-findelements-commands-examples
-
请同时发布语法错误。
-
尝试将元素设置为变量,但我收到“未定义子或函数错误”```Sub Test() Dim bot Set bot = CreateObject("Selenium.WebDriver") Dim元素集 Element = FindElement(By.linkText("afterpaytouch.com/images/…))
标签: vba selenium-webdriver web-scraping