0
0
Selenium Javatesting~20 mins

File download handling in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
File Download Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Selenium Java code snippet for file download?
Consider the following Selenium Java code that sets up a Firefox profile to automatically download PDF files without showing the download dialog. What will be the value of downloadDir after execution?
Selenium Java
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir", "/tmp/downloads");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf");

WebDriver driver = new FirefoxDriver(new FirefoxOptions().setProfile(profile));
String downloadDir = profile.getString("browser.download.dir");
A"/tmp/downloads"
B"C:\\Users\\Downloads"
C"/home/user/Downloads"
D""
Attempts:
2 left
💡 Hint
Look at the preference set for "browser.download.dir" in the Firefox profile.
assertion
intermediate
1:30remaining
Which assertion correctly verifies the downloaded file exists?
You have downloaded a file named "report.pdf" to the directory "/tmp/downloads". Which assertion correctly checks that the file exists using Java's JUnit?
Selenium Java
File downloadedFile = new File("/tmp/downloads/report.pdf");
AassertNull(downloadedFile);
BassertEquals(true, downloadedFile.isDirectory());
CassertFalse(downloadedFile.exists());
DassertTrue(downloadedFile.exists());
Attempts:
2 left
💡 Hint
Check the method that verifies if a file exists on disk.
🔧 Debug
advanced
2:30remaining
Why does this Selenium Java code fail to download the file automatically?
Review the code below. The test expects to download a CSV file automatically, but the browser shows a download dialog instead. What is the main reason?
Selenium Java
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir", "/tmp/downloads");
// Missing setting for MIME type

WebDriver driver = new FirefoxDriver(new FirefoxOptions().setProfile(profile));
driver.get("http://example.com/download.csv");
AThe driver.get() method does not trigger downloads.
BThe download directory path is invalid.
CThe MIME type for CSV files is not set in "browser.helperApps.neverAsk.saveToDisk" preference.
DFirefoxProfile is deprecated and cannot be used.
Attempts:
2 left
💡 Hint
Check if the browser knows which file types to download automatically.
framework
advanced
2:00remaining
Which Selenium Java framework feature helps verify file download completion?
In automated tests, which approach best ensures that a file has finished downloading before assertions run?
AUse explicit waits to check the file exists and its size is stable over time.
BUse Thread.sleep() for a fixed time after triggering download.
CCheck only the file name in the download directory immediately after download starts.
DRely on browser logs to confirm download completion.
Attempts:
2 left
💡 Hint
Think about waiting for a condition rather than a fixed delay.
🧠 Conceptual
expert
3:00remaining
What is the best practice for handling file downloads in Selenium tests to avoid flaky tests?
Choose the best practice to handle file downloads in Selenium automated tests to ensure reliability and maintainability.
AManually click the download dialog buttons using Selenium WebDriver actions.
BConfigure browser profile to auto-download files to a dedicated temp folder and verify file presence with explicit waits.
CUse default browser settings and rely on manual verification of downloads.
DDisable downloads and mock file content instead.
Attempts:
2 left
💡 Hint
Think about automation stability and avoiding UI dialogs.