Downloading file through Selenium Webdriver in python

前端 未结 1 1738
予麋鹿
予麋鹿 2020-12-03 20:09

I am writing a program to automate web interaction through selenium webdriver in python. I got stuck in last step when I click on the \"download\" button through script, a w

相关标签:
1条回答
  • 2020-12-03 20:27

    While you work with a new FirefoxProfile, use the set_preference method to configure the profile in such a way so clicks on Save and Ok and it doesn't gets interrupted in the downloading process. You can set the configuration as follows:

    profile = webdriver.FirefoxProfile()
    profile.set_preference("browser.download.dir",os.getcwd());
    profile.set_preference("browser.download.folderList",2);
    profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/csv,application/excel,application/vnd.msexcel,application/vnd.ms-excel,text/anytext,text/comma-separated-values,text/csv,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/octet-stream");
    profile.set_preference("browser.download.manager.showWhenStarting",False);
    profile.set_preference("browser.helperApps.neverAsk.openFile","application/csv,application/excel,application/vnd.msexcel,application/vnd.ms-excel,text/anytext,text/comma-separated-values,text/csv,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/octet-stream");
    profile.set_preference("browser.helperApps.alwaysAsk.force", False);
    profile.set_preference("browser.download.manager.useWindow", False);
    profile.set_preference("browser.download.manager.focusWhenStarting", False);
    profile.set_preference("browser.download.manager.alertOnEXEOpen", False);
    profile.set_preference("browser.download.manager.showAlertOnComplete", False);
    profile.set_preference("browser.download.manager.closeWhenDone", True);
    profile.set_preference("pdfjs.disabled", True);
    
    0 讨论(0)
提交回复
热议问题