So I am working on automating a website using Selenium and VBA. This website has a download button which upon clicking will download a .xls file to my downloads folder. I want to set a download path for this file, ie. instead of its default download location i want to give another path (ex.- C:\Users\folder). I tried searching ways to achieve this but the codes were mostly for Python, Java and some using PowerShell but i want a code that can be run from VBA. My code is as follows and am working on MS Edge.
Dim c As Selenium.WebDriver
Set c = New Selenium.WebDriver
c.Start "edge"
c.Get "https://......" 'cannot share as its our company's internal website
c.Window.Maximize
c.ExecuteScript ("window.scrollTo(0, document.body.scrollHeight);")
c.Wait (3000)
c.FindElementByXPath("//*[@id='ctl00_ctl40_g_01b3ceb6_dac0_4ca9_a746_e3189ac6706d_ctl00_spgvInvoiceList_ctl03_imageButtonShowPDF']").Click 'the download button
End Sub
Any tips would be extremely helpful.
CodePudding user response:
Here is code
Dim driver As New Selenium.ChromeDriver
driver.SetPreference "download.default_directory", "C:\Folder\"
driver.SetPreference "download.directory_upgrade", True
driver.SetPreference "download.prompt_for_download", False
driver.Get "https://www.google.com/
The "C:\Folder" is where you put the folder you want.
CodePudding user response:
The code provided by Akzy works in Chrome but not in Edge. However, I've tested relevant arguments for SetPreference, and found that they just not work in Edge. It might have something to do with the fact that SeleniumBasic uses Selenium version 2 while the latest version of Selenium is recommended in the official doc. But I'm afraid you have to run the automation via other languages like c# and Python.