0

I am trying to automatically download files from a pop up dialog using selenium-python. I need it to press 'ok'

I already tried creating a profile but I'm not sure how i can make it work with the driver i'm using to navigate through the website.

driver=webdriver.Firefox(executable_path=r"C:\Users\blank\Downloads\archives\geckodriver.exe")
driver.get("website")
.
.
.
.
#navigating through the page
driver.find_element(By.LINK_TEXT, "Download").click()
#pop up dialog box comes up need to automate saying yes

1 Answers1

0

Try adding the following option, so that the file should be downloaded without any additional steps.

FF_options = Options()
FF_options.set_preference("browser.download.folderList",2)

# <== you might have to change the download content type based on your file type in the below line.

FF_options.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/pdf")
FF_options.set_preference("browser.download.dir", "/Path/to/directory")
FF_options.set_preference("pdfjs.disabled", True)

driver=webdriver.Firefox(executable_path=r"C:\Users\blank\Downloads\archives\geckodriver.exe", firefox_options=FF_options)
.
.
.
#navigating through the page
driver.find_element(By.LINK_TEXT, "Download").click()
supputuri
  • 13,644
  • 2
  • 21
  • 39
  • And if you want to wait until the file download is completed and get the file name just downloaded then refer to [this](https://stackoverflow.com/questions/56543995/how-to-get-the-url-or-filename-being-downloaded-now/56554342#56554342) post. – supputuri Jul 25 '19 at 17:53
  • For FF_options.set_preference("browser.download.dir", "/Path/to/directory") portion of the code what are you refering to. for both arguments so I could put the correct data. – learningguy Jul 25 '19 at 19:06
  • Location where you want to download the file. Generally it might be your downloads folder path. – supputuri Jul 25 '19 at 19:16
  • For Path to Directory I put the location I want the file to be stored. When I ran the code you gave me the popup still came :( – learningguy Jul 25 '19 at 19:17
  • what's the file extension that's downloading? – supputuri Jul 25 '19 at 19:17
  • csv. I went ahead and replaced "application/pdf" to "text/csv" mime in FF_options.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/pdf") – learningguy Jul 25 '19 at 19:22