Python中的Selenium - 下载对话框仍然打开

时间:2015-05-04 03:23:28

标签: python python-2.7 selenium selenium-webdriver

我已应用所有配置以防止下载窗口弹出,但仍然出现,即使在FF中的Option中,配置也设置为“将文件保存到”。它让我发疯,请帮忙:

    profile = webdriver.firefox.firefox_profile.FirefoxProfile()

    profile.set_preference("browser.download.folderList", 2) # custom location
    profile.set_preference("browser.download.manager.showWhenStarting", False)
    profile.set_preference("browser.download.dir", path)
    profile.set_preference('browser.helperApps.neverAsk.saveToDisk', ('text/tsv'))
    profile.set_preference("webdriver_enable_native_events", False)

    profile.set_preference("browser.download.manager.scanWhenDone",False)
    profile.set_preference("browser.download.manager.useWindow",False)
    profile.set_preference("browser.helperApps.alwaysAsk.force",False)
    #profile.set_preference('browser.download.dir', os.getcwd())   

'text/plain, application/vnd.ms-excel, text/tsv, text/comma-separated-values, application/octet-stream, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')

    profile.update_preferences()   

    driver = webdriver.Firefox(firefox_profile=profile)
    driver.implicitly_wait(60)
    base_url ="the base url"

1 个答案:

答案 0 :(得分:0)

尝试

profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/force-download")

无论如何,以下内容适用于我:

profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)

profile..set_preference("browser.helperApps.neverAsk.saveToDisk", "application/force-download")
profile..set_preference("browser.download.panel.shown", True)