How to Handle Common Selenium Challenges Using Python?

Contents

0tuzjszfeo1zbjosa-6625651
Photo by Olav Ahrens Røtne about Unsplash

How to download files using Selenium WebDriver

import

download_dir = os.getcwd()# current working directory

profile = webdriver.FirefoxProfile()

profile.set_preference("browser.download.folderList", 2) # the custom location specified browser.download.dir is enabled when browser.download.folderList equals 2
profile.set_preference('browser.download.dir', download_dir)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.dir", path)
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', CONTENT_TYPE)
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.update_preferences()

browser = webdriver.Firefox(firefox_profile=profile)
Graphical interface to retrieve MIME type
Subscribe to our Newsletter

We will not send you SPAM mail. We hate it as much as you.