0

I am trying to download an Excel file from a website using VBA Selenium. However I am getting the error:

Object Does not Support This Property or Method (Error 438)

Here is the html:

<a href="../Shared/RepositoryFileServer.ashx? 
fieldId=26737&amp;Type=Attachment" id = "DownloadLink" 
class="SystemURL">click her</a> == $0

Here is the line of code that is causing the error:

.FindElementbyCssSelector("a[href*='Type=Attachment']").Click

I have also tried these:

.FindElementbyID("DownloadLink").Click

.FindElementbyXpath(".//a[contains(@href,'Type=Attachment')]").Click

.FindElementByClass("SystemURL").Click
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Steo
  • 1
  • 1
  • 1
    post your code please – 0m3r Jun 07 '22 at 20:47
  • If you can extract the href from the link you may be able to open the file using `Workbooks.Open(urlHere)` – Tim Williams Jun 07 '22 at 20:54
  • @TimWilliams Thank you for your comment. The url changes with each download. I would not get the most updated data if I open the link as you suggested – Steo Jun 08 '22 at 04:14
  • I wasn't suggesting you hard-code the link, only pull it from the page and use then Excel to access the file at that URL instead of having to handle the file download from the browser. – Tim Williams Jun 08 '22 at 05:29

1 Answers1

0

Considering the following HTML:

<a href="../Shared/RepositoryFileServer.ashx?fieldId=26737&amp;Type=Attachment" id = "DownloadLink" class="SystemURL">click her</a>

To click() on the element you can use either of the following locator strategies:

  • Using FindElementbyCss:

    .FindElementbyCss("a.SystemURL#DownloadLink[href$='Attachment']").Click
    
  • Using FindElementbyXpath:

    .FindElementbyXpath("//a[@class='SystemURL' and @id='DownloadLink'][contains(@href, 'Attachment')]").Click
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you for your comment. Per your recommendation I tried FindElementByCss and still got the '438 Error' and then tried FindElementbyXpath which gave me 'Run-time Error 7. No Such Element Error'. Any other ideas? Is there any other information I can provide? – Steo Jun 08 '22 at 03:44
  • @Steo It's okay to face **`'Run-time Error 7. No Such Element Error'`**. Check [this](https://stackoverflow.com/a/47995294/7429447) or [this](https://stackoverflow.com/a/48472940/7429447) discussion. – undetected Selenium Jun 08 '22 at 05:49