Home » excel » excel – Why is my VBA code unable to select "Download" in order to download a .xls file this specific website?

excel – Why is my VBA code unable to select "Download" in order to download a .xls file this specific website?

Posted by: admin May 14, 2020 Leave a comment

Questions:

Good morning,

I am wondering why my code does not work on this site in particular. I would like to be able to have it press “Download” in order to initiate the process for downloading an .xls file. However, it does not and I am unable to figure it out.

Public IE As InternetExplorer

Public Sub Main()
  Call InitiateIE
  IE.navigate ("https://www.auction.com/event/details/E-11142/?filter=reset")
  Call LoadIE
  IE.Document.getElementsByClassName("button-root_button_jzfF button-role-default_button_3iu5 button-is-medium_button_3vqd navigation-btn_styles_M1TS download-inventory-btn_styles_3ytA navigation-container-element_styles_3MZ0")(0).Click
  Call LoadIE
  IE.Quit
End Sub

Private Sub InitiateIE()
  Set IE = New InternetExplorer
  IE.Visible = True
End Sub

Private Sub LoadIE(Optional BufferTime As Long = 1000)
  Do While IE.Busy
  Loop
  Do Until IE.Document.ReadyState = "complete" Or IE.Document.ReadyState = "interactive"
  Loop
End Sub
How to&Answers:

As an aside I would go with an attribute = value CSS selector btw

ie.document.querySelector("[data-elm-id='event_details_download_auction_inventory']").Click

Selenium Basic with Chrome:

Option Explicit
Public Sub GetDownload()
'VBE > Tools > References > Selenium Type Library
'Requires latest chrome browser and chrome driver
'Chrome driver containing folder must be on environmental path
'Download selenium https://github.com/florentbr/SeleniumBasic/releases/tag/v2.0.9.0
    Dim d As WebDriver
    Set d = New ChromeDriver
    Const URL = "https://www.auction.com/event/details/E-11142/?filter=reset"

    With d
        .Start "Chrome"
        .get URL
        .FindElementByCss("[data-elm-id='event_details_download_auction_inventory']").Click
        .Quit
    End With
End Sub

Other selenium info

Environmental path – the driver must sit in a folder which is on this path.