Challenge - 5 Problems
File Download Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Selenium Python code snippet for file download?
Consider the following Selenium Python code that sets up a Firefox profile to automatically download PDF files without showing the download dialog. What will be the value of
download_dir after the code runs?Selenium Python
from selenium import webdriver from selenium.webdriver.firefox.options import Options options = Options() profile = webdriver.FirefoxProfile() download_dir = '/tmp/downloads' profile.set_preference('browser.download.folderList', 2) profile.set_preference('browser.download.dir', download_dir) profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/pdf') profile.set_preference('pdfjs.disabled', True) driver = webdriver.Firefox(firefox_profile=profile, options=options) print(download_dir)
Attempts:
2 left
💡 Hint
Look at the variable assigned to
download_dir and what is printed.✗ Incorrect
The variable
download_dir is set to the string '/tmp/downloads' and then printed. The Selenium preferences use this variable but do not change its value.❓ assertion
intermediate1:30remaining
Which assertion correctly verifies a file was downloaded?
You want to check if a file named 'report.pdf' exists in the download directory after triggering a download in Selenium Python. Which assertion is correct?
Selenium Python
import os file_path = '/tmp/downloads/report.pdf' # Which assertion below correctly checks the file exists?
Attempts:
2 left
💡 Hint
Use the function that checks if a path is a file.
✗ Incorrect
os.path.isfile(file_path) returns True if the path exists and is a file. This is the correct way to assert the file was downloaded.
🔧 Debug
advanced2:30remaining
Why does this Selenium Python code fail to download the file automatically?
This code is intended to download CSV files automatically without a dialog, but the download dialog still appears. What is the likely cause?
Selenium Python
from selenium import webdriver profile = webdriver.FirefoxProfile() profile.set_preference('browser.download.folderList', 2) profile.set_preference('browser.download.dir', '/tmp/downloads') profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'text/csv') driver = webdriver.Firefox(firefox_profile=profile) driver.get('http://example.com/download.csv')
Attempts:
2 left
💡 Hint
Check if FirefoxProfile is still supported in recent Selenium versions.
✗ Incorrect
Recent Selenium versions deprecate FirefoxProfile usage. The profile settings may be ignored, causing the download dialog to appear.
🧠 Conceptual
advanced2:00remaining
What is the best way to wait for a file download to complete in Selenium Python?
You trigger a file download in Selenium Python. The file may take some seconds to appear in the download folder. Which approach best waits for the download to finish?
Attempts:
2 left
💡 Hint
Waiting for file size to stop changing is a reliable method.
✗ Incorrect
Polling the folder and checking that the file exists and its size does not change over a short period ensures the download is complete.
❓ framework
expert3:00remaining
How to configure ChromeDriver in Selenium Python to download files without prompt?
You want to configure ChromeDriver to download files automatically to '/tmp/downloads' without showing the download prompt. Which code snippet correctly sets this up?
Attempts:
2 left
💡 Hint
ChromeOptions uses add_experimental_option to set preferences.
✗ Incorrect
ChromeOptions requires adding preferences via add_experimental_option with a dictionary of prefs. Other methods are invalid or ignored.