Jump to content
Sign in to follow this  
jack_

Not able to toggle dialog box using selenium in Python

Recommended Posts

I am using "Python-3.4.1 32 bit" on "Windows 7 64 bit" machine with "Selenium" using "Firefox 33". I am trying to automate downloading a "CSV" file from a secured website after furnishing the necessary credentials. I have written the required code to navigate to the correct element to initiate the download of the file but I am stuck when Firefox gives the download box (Dialog box title: Opening export.csv, "Open with" and "Save File" options as radio buttons with "OK" and "Cancel" as buttons). I want the file to be downloaded automatically and for that I have tried the following codes without success:

from selenium import webdriverfp = webdriver.FirefoxProfile()fp.set_preference("browser.download.manager.showWhenStarting",False)fp.set_preference("browser.download.folderList",2)fp.set_preference("browser.download.dir", "C:UsersarunDownloads")fp.set_preference("browser.download.downloadDir", "C:UsersarunDownloads")fp.set_preference("browser.download.defaultFolder", "C:UsersarunDownloads")fp.set_preference('browser.helperApps.neverAsk.saveToDisk',"text/csv")driver = webdriver.Firefox(fp)driver.get("http://website-url.com")

and then click on the button to start the download. But, it still shows the dialog box. I even tried handling it as an alert and tried

alert = driver.switch_to_alert()alert.accept()

but this always gave an exception of alert not found which led me to the conclusion that it might not be a JavaScript functionality after all but rather a web element. I am giving sufficient delay for the alert box to appear before I try to interact with it using the "alert" object code shown above.What do I do to get this downloaded automatically without the dialog box interaction (the way it's handled in Google Chrome browsers)I think that the server is not assigning the correct MIME type for the file that is being downloaded? The file I am downloading is of type: "text/csv" and in Firefox when the dialog box appears, "Do this automatically for files like this from now on" check box is greyed out.Thanks for your help and timeCheers!

Share this post


Link to post
Share on other sites

It looks like your best bet is to get Firefox to save automatically instead of trying to manipulate the download dialog box.http://stackoverflow.com/questions/1176348/access-to-file-download-dialog-in-firefoxThey mention mime types there also.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...