Python Selenium Chromedriver how to download pdf without opening file explorer?

Viewed 144

I'm trying to figure out a way to download this file at a click of a button (right now it just opens file explorer). I'm looking for a way to make it immediately download into a folder. Here is my code, any help is appreciated. Thank you!

options = webdriver.ChromeOptions()
options.add_experimental_option('prefs', {
"download.default_directory": r"C:\Users\jhak\downloads", #Change default directory for downloads
"download.prompt_for_download": False, #To auto download the file
"download.directory_upgrade": True,
"plugins.always_open_pdf_externally": True,
"profile.default_content_setting_values.notifications":2,
"download.extensions_to_open": "applications/pdf"
#It will not show PDF directly in chrome
})

options.add_argument("--disable-notifications")

global chrome_browser
chrome_browser = webdriver.Chrome(r'C:\Users\rlaceste\Desktop\chromedriver.exe', options = options)
chrome_browser.maximize_window()

#element that holds download link
chrome_browser.find_element_by_id('element here').click()
0 Answers
Related