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

后端 未结 10 1349
死守一世寂寞
死守一世寂寞 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:12

    I've discovered a useful solution that hopefully will help somebody out there.

    You can skip the prompt altogether with firefox if you're starting the download with a click by holding the ALT key.

    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.common.action_chains import ActionChains
    ...
    profile.set_preference("browser.altClickSave", True)
    ...
    element = driver.find_element_by_xpath("//a")
    ActionChains(driver).key_down(Keys.ALT).click(element).key_up(Keys.ALT).perform()
    

    This should download any file without needing to specify MIME type of anything.

提交回复
热议问题