0

How do I write code in python using selenium driver to click on save file > do this automaticlly for these files and click on okay as shown in the image? enter image description here

I'm using pyhon 3.8 and the firefox browser

toydarian
  • 4,246
  • 5
  • 23
  • 35

1 Answers1

3

a better approach will be to directly download the file

from selenium import webdriver

# To prevent download dialog from opening
ff_profile = webdriver.FirefoxProfile()
ff_profile.set_preference('browser.download.manager.showWhenStarting', False)
ff_profile.set_preference('browser.helperApps.neverAsk.saveToDisk','application/xls;text/csv')

browser = webdriver.Firefox(profile)
browser.get("<url>")

browser.find_element_by_id('<file_element_id>').click()

above code will download the file to the default location. if you want to download somewhere else add the following lines:

profile.set_preference('browser.download.folderList', 2) # custom downlaod location
profile.set_preference('browser.download.dir', '<your_path>')
yogev
  • 189
  • 5