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

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

    Based on Amey's answer 1) and of course Yi Zeng's blog (in ruby) quoting Selenium itself doesn’t interact with system-level dialogs like this as well as the documentation, here is the python snippet to resolve the issue

    from selenium import webdriver
    from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
    
    profile = FirefoxProfile()
    profile.set_preference("browser.helperApps.neverAsk.saveToDisk", 'application/pdf')
    driver = webdriver.Firefox(firefox_profile=profile)
    
    driver.get(target_url)
    #specific to target_url
    driver.find_element_by_css_selector('a[title="Click to Download"]').click()
    

提交回复
热议问题