1

I am trying to download files by clicking a button. This works fine as long as my ChromeDriver is not in headless mode. Once I tested the macro with ChromeDriver in headless mode, I realized that nothing was being downloaded. I researched the issue and found out that it was a security measure. There are suggested work-arounds for Python, however I was not able to translate the code into VBA. I am using SeleniumBasic.

What I want is to be able to download files to the Environ("userprofile") & "\Downloads\" folder once I click a download button, just like I do when the browser is not in headless mode. Thank you all in advance.

Notes:

  • I call the driver in headless mode using driver.AddArgument "--headless"
  • I could not provide the URL I am using as this is a long macro requiring login etc. but as far as I understand, the issue should be reproducible in any download scenario involving a headless ChromeDriver.
  • I am using the most recent SeleniumBasic v2.0.9.0 and the ChromeDriver version 75.0.3770.140
Lorne
  • 181
  • 2
  • 11
  • you might be able to use driver.executeScript to run [this](https://stackoverflow.com/a/45668964/6241235]) as a string you pass as arg. Though update paths and escape ". The other answer in your link I don't think can be translated. – QHarr Sep 28 '19 at 11:59
  • I am not sure what that would look like :/ I am open to try it out if you could convert it into familiar syntax. I know a little about using driver.executeScript, mainly for scrolling, but in this case I am lost as to what would be the string and what would be the remaining arguments. – Lorne Sep 28 '19 at 12:06
  • it would be driver.executeScript(s) where s is the string in that answer. The string would need to be wrapped in "" meaning any inside " needs to be doubled up to escape. You would also use _ to break across lines. Bit like you see here: https://github.com/florentbr/SeleniumBasic/issues/85 – QHarr Sep 28 '19 at 12:13
  • based on comments under that answer you might find this won't work on later versions anyway. – QHarr Sep 28 '19 at 12:19
  • I haven't been able to use the headless option for about a year and I am interested in knowing how this plays out. After my headless scripts broke, I noticed that I can't minimize an automated window or even partially cover it without interrupting browser automation. Having an automated solution if far more important to me than having a silent automated solution so I haven't looked for a way to run headless again. I don't even know if I would have the same problem if I moved away from Selenium and Chrome by converting to IE. Too much time, too little reward. – ProfoundlyOblivious Sep 28 '19 at 18:50
  • You need to use ChromeDriver 77.0.3865.10 - 'Support to save file downloads in headless mode' . https://chromedriver.chromium.org/downloads – Rahul L Sep 30 '19 at 05:13
  • @RahulL thank you for the response. The latest version of SeleniumBasic is only compatible with v75.0.3770.140 as far as I know. I have given up on this for now, working without clientless. – Lorne Sep 30 '19 at 11:17

0 Answers0