0

Trying to click a download button on Chrome using Selenium Type Library. The code below is one that I picked up off the boards but I am receiving a Syntax Error

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
5
  • You probably want to dim bot as an` Object` instead of an assumed Variant, but that probably will not fix the problem. Please explain what line you are getting the error on. You forgot to include that in your question. Commented Nov 29, 2019 at 23:27
  • The error is on the bot.FindElement line - I can open the webpage fine but cannot click the download button Commented Nov 29, 2019 at 23:35
  • instead of trying to click it all in one line, set the element to a variable first, and then check to see if the variable gets set to something first. If not, then it could not find the element. My best guess is that you do not want to include the entire path to the element. - techbeamers.com/findelement-and-findelements-commands-examples Commented Nov 29, 2019 at 23:44
  • 1
    Please post the syntax error as well. Commented Nov 29, 2019 at 23:45
  • Tried the set the element as a variable but I am receiving a 'Sub or Function not defined error' ```Sub Test() Dim bot Set bot = CreateObject("Selenium.WebDriver") Dim Element Set Element = FindElement(By.linkText("afterpaytouch.com/images/…)) Commented Nov 30, 2019 at 0:16

1 Answer 1

1

I would add a reference to Selenium Type Library in VBE > Tools > References then use early bound reference, full url and apply VBA selenium basic syntax to find link by css and click

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.