GWD
GWD

Reputation: 4008

Handling file download popup of chromium browsers using VBA

I'm using Selenium with VBA and Microsoft Edge to collect information, and download some files from a webpage. Everything works great except for the downloading part.

On this example site: https://file-examples.com/index.php/sample-documents-download/sample-doc-download/, Code like

oWebDriver.FindElementByXPath("//a[@href=""https://file-examples-com.github.io/uploads/2017/02/file-sample_100kB.doc""]").Click

will result in a popup like this:

enter image description here

Unfortunately, it is not possible to simply change the browser's preferences in my case, because the macro will be running on a machine with limited authorization and the following setting can not be changed:

enter image description here

The last option can be translated to: "Ask for the storage location with every download" and it is locked.

It seems that the "Save As" popup in the first screenshot can't be accessed, neither with Selenium nor with SendKeys.

So the only option seems to be using the Windows API with VBA to somehow automate this step, however, even so, it seems to be impossible to get a handle on this pesky popup. I tried finding the window with Spy++ and it doesn't seem to show up as a separate window: enter image description here

The only solution I can now think of is getting the window size of the parent Edge browser window, navigating the mouse to the approximate position of the "Save As" button, and clicking it there using VBA and the Windows API. Obviously, This is not a great solution, as it would be quite frail and can easily break with the smallest misalignment.

Is there any other way to automate this step that doesn't require moving the mouse and automating the "manual" clicking, using only VBA with Selenium?

Upvotes: 1

Views: 1197

Answers (1)

Yu Zhou
Yu Zhou

Reputation: 12999

Selenium only works for browser web page automation. The pop-up is not a part of the wab page so Selenium will not be able to recognize it.

And I think any setting in Selenium including "download.prompt_for_download" won't have effect. The pop-up is controlled by the browser setting, and the browser setting is controlled by your group policy, you can't override it with Selenium settings.

I think the only way is to use some 3rd party UI automation library to click that option along with Selenium, just like what you said in the question.

Upvotes: 1

Related Questions