Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.7k points)

Ok so far I have my programing going to the website I want to download links from and selecting it, then the firefox dialogue box shows up and I don't know what to do. I want to save this file to a folder on my desktop. I am using this for a nightly build so I need this to work. Please help.

Here is my code that grabs the download link from the website:

driver = web driver.Firefox()


driver.get("Name of web site I'm grabbing from")

driver.find_element_by_xpath("//a[contains(text(), 'DEV.tgz')]".click()

1 Answer

0 votes
by (62.9k points)

You need to make Firefox save this explicit file type automatically.

This can be achieved by setting browser.helperApps.neverAsk.saveToDisk preference:

from selenium import webdriver

profile = webdriver.FirefoxProfile()

profile.set_preference("", 2)

profile.set_preference("", False)

profile.set_preference("", 'PATH TO DESKTOP')

profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/x-gzip")

driver = webdriver.Firefox(firefox_profile=profile)

driver.get("Name of web site I'm grabbing from")

driver.find_element_by_xpath("//a[contains(text(), 'DEV.tgz')]").click()

More explanation: tells it to not use default Downloads directory turns of showing download progress sets the directory for downloads

browser.helperApps.neverAsk.saveToDisk tells Firefox to automatically download the files of the chosen mime-types

You can read of these preferences at about: config within the browser.

There is additionally a really elaborated documentation page accessible here: About:config entries.

Besides, rather than using XPath approach, I'd use find_element_by_partial_link_text():


Also, see:

Access to file download dialog in Firefox

Firefox + selenium WebDriver and download a CSV file automatically

If you wish to Learn Selenium visit this Selenium Certification.

Browse Categories