How to handle open file popup using selenium

702 Views Asked by At

When I navigate to certain URL, the browser prompts me to open a file:

enter image description here

How can I select "Open" when controlling the browser via selenium? Can I set some options to the webdriver to automatically open files? I am using Microsoft Edge.

My current solution is to use keyboard module and press tabulator and enter to click the open-button, but I would like to do this so that the keyboard-module wouldn't be needed and I would be able to run selenium in headless mode.

Also, if there is another way to do this than by using selenium, feel free to suggest. Thank you in advance!

1

There are 1 best solutions below

2
On

First of all you should understand if it is a browser prompt or a prompt from the website. In the first case, Selenium can't handle it.

If it is a website prompt, you should try

IAlert alert = _DRIVER.SwitchTo().Alert();

//accept the alert
alert.Accept();

//dismiss the alert
alert.Dismiss();

Wrote it C#, but I think is the same thing in Python.