Python and selenium : firefox keep creating dialog boxes when downloading even if i set its preferences Python and selenium : firefox keep creating dialog boxes when downloading even if i set its preferences selenium selenium

Python and selenium : firefox keep creating dialog boxes when downloading even if i set its preferences


I've had issues with that too. I've just done this instead. Note: it does take more time so if you have a ton of files you're downloading, this may not be worth it. Otherwise, this will do the trick.

Create an alert object that's ready to be used on the dialogue boxes, like this for example:

alert = driver.switch_to_alert()

Import Expected Conditions:

from selenium.webdriver.support import expected_conditions as EC

Then, create a function that directs the browser to wait until the expected condition (the alert) is prompted.

WebDriverWait(browser, 3).until(EC.alert_is_present()except TimeoutException:

It's best to put this is a try/except block, but not mandatory.

Then, simply use the 'accept' method of the alert object to confirm the download after selenium has taken control of the alert window:

alert.accept()

The function could look something like this:

    try:        alert = driver.switch_to_alert()        alert_wait()        alert.accept()    except print('No alertfound')

Also, I would highly recommend using the requests/BeautifulSoup module for this so you don't have to render the browser and experience the delays that come with navigating through a ton of web pages. The requests module does it all behind the scenes. This gets tricky if you need to enter a password prior to downloading. If not, the BeautifulSoup library is awesome for scraping tags/hrefs, collecting them in a list, and then looping over them one by one using the similar requests.get() method.

In fact, the last time I had this problem, I used the requests module instead of selenium and the alert windows were automatically accepted. Lightening fast, too.


First of all, why are you using beautifulsoup?! Make use of driver.find_element_by_css_selector

Secondly, please confirm that the PDF file you're targetting actually has the appropriate mimetype. See http://yizeng.me/2014/05/23/download-pdf-files-automatically-in-firefox-using-selenium-webdriver/