Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access to file download dialog in Firefox

Is there any kind of API that can allow me to manipulate a file download dialog in Firefox? (I want to access the one that appears when user does something, not initiate one myself).

What I want to do is to access this dialog from Selenium (and whether Selenium "privileged mode" is enough to access chrome interface is something I am not sure about as well).

like image 295
Andrey Shchekin Avatar asked Jul 24 '09 08:07

Andrey Shchekin


People also ask

How do I show download options in Firefox?

Right-clickHold down the control key while you click the Downloads button for options, such as to hide the Downloads button when there are no downloads in the current session or to show the Downloads panel when a download begins.

How do I get Firefox to ask where to save Downloads?

Chosen SolutionClick the Firefox button, go to Options | Options | General and in the Downloads menu, checkmark the option "'''Always ask me where to save files'''".

Where is the Firefox download folder?

In Firefox, click the “Open menu” button on the right side of the toolbar and then click “Settings” in the drop-down menu. On the “General” page, look for the settings in the “Files and Applications” section. Click the “Browse” button and locate (or create) your new download folder.


4 Answers

I have a solution for this issue, check the code:

FirefoxProfile firefoxProfile = new FirefoxProfile();

firefoxProfile.setPreference("browser.download.folderList",2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false);
firefoxProfile.setPreference("browser.download.dir","c:\\downloads");
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv");

WebDriver driver = new FirefoxDriver(firefoxProfile);//new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);

driver.navigate().to("http://www.myfile.com/hey.csv");
like image 58
dlopezgonzalez Avatar answered Nov 08 '22 02:11

dlopezgonzalez


I was stuck with the same problem, but I found a solution. I did it the same way as this blog did.

Of course this was Java, I've translated it to Python:

fp = webdriver.FirefoxProfile()

fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)
fp.set_preference("browser.download.dir",getcwd())
fp.set_preference("browser.helperApps.neverAsk.saveToDisk","text/csv")

browser = webdriver.Firefox(firefox_profile=fp)

In my example it was a CSV file. But when you need more, there are stored in the ~/.mozilla/$USER_PROFILE/mimeTypes.rdf

like image 43
Akendo Avatar answered Nov 08 '22 00:11

Akendo


Not that I know of. But you can configure Firefox to automatically start the download and save the file in a specific place. Your test could then check that the file actually arrived.

like image 42
Aaron Digulla Avatar answered Nov 08 '22 01:11

Aaron Digulla


Web Applications generate 3 different types of pop-ups; namely,

 1| JavaScript PopUps
 2| Browser PopUps
 3| Native OS PopUps [e.g., Windows Popup like Upload/Download]

In General, the JavaScript pop-ups are generated by the web application code. Selenium provides an API to handle these JavaScript pop-ups, such as Alert.

Eventually, the simplest way to ignore Browser pop-up and download files is done by making use of Browser profiles; There are couple of ways to do this:

  • Manually involve changes on browser properties (or)
  • Customize browser properties using profile setPreference

Method1

Before you start working with pop-ups on Browser profiles, make sure that the Download options are set default to Save File.

(Open Firefox) Tools > Options > Applications

enter image description here

Method2

Make use of the below snippet and do edits whenever necessary.

FirefoxProfile profile = new FirefoxProfile();

String path = "C:\\Test\\";
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir", path);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/msword, application/csv, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream");
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.manager.focusWhenStarting", false);  
profile.setPreference("browser.download.useDownloadDir", true);
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.download.manager.closeWhenDone", true);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.useWindow", false);
profile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);
profile.setPreference("pdfjs.disabled", true);
       
driver = new FirefoxDriver(profile);
like image 10
Prashanth Sams Avatar answered Nov 08 '22 02:11

Prashanth Sams