How do I automatically download files from a pop up dialog using selenium-python

后端 未结 10 1329
死守一世寂寞
死守一世寂寞 2020-12-16 13:19

I am trying to automatically download files from a pop up dialog using selenium-python.

The firefox popups look like this

10条回答
  •  有刺的猬
    2020-12-16 14:18

    In python, but this will work in Java as well because the firefox preferences are a javascript:

    profile.set_preference("browser.download.panel.shown", False)
    profile.set_preference("browser.helperApps.neverAsk.openFile","text/csv,application/vnd.ms-excel")
    profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/csv,application/vnd.ms-excel")
    profile.set_preference("browser.download.folderList", 2);
    profile.set_preference("browser.download.dir", "c:\\firefox_downloads\\")
    browser = webdriver.WebDriver(firefox_profile=profile)
    

    this works for CSV files, modify it for whatever filetype you are downloading.

提交回复
热议问题