Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to set the download directory in ChromeOptions.
Selenium Java
ChromeOptions options = new ChromeOptions(); Map<String, Object> prefs = new HashMap<>(); prefs.put("download.default_directory", [1]); options.setExperimentalOption("prefs", prefs);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using an invalid path string or missing quotes.
Setting the preference key incorrectly.
✗ Incorrect
The download.default_directory preference must be set to the desired download folder path as a string.
2fill in blank
mediumComplete the code to wait until the file is downloaded by checking the file existence.
Selenium Java
File file = new File("C:/Downloads/report.pdf"); WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30)); wait.until(driver -> [1]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using isDirectory() which checks if the path is a folder.
Using canRead() or isHidden() which do not confirm file presence.
✗ Incorrect
To confirm the file is downloaded, we wait until the file exists in the download folder.
3fill in blank
hardFix the error in the code that tries to delete the downloaded file after test completion.
Selenium Java
File downloadedFile = new File("C:/Downloads/report.pdf"); if ([1]) { downloadedFile.delete(); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using isDirectory() which is false for files.
Using canWrite() which checks permissions but not existence.
✗ Incorrect
Before deleting, check if the file exists using exists() method to avoid errors.
4fill in blank
hardFill both blanks to configure Firefox profile to auto-download PDF files without prompt.
Selenium Java
FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.download.folderList", [1]); profile.setPreference("browser.helperApps.neverAsk.saveToDisk", [2]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using folderList 1 which is default downloads folder.
Setting wrong MIME type that does not match PDF files.
✗ Incorrect
Setting folderList to 2 uses a custom folder, and neverAsk.saveToDisk to "application/pdf" disables the save prompt for PDFs.
5fill in blank
hardFill all three blanks to create a test that clicks a download link, waits for the file, and asserts its existence.
Selenium Java
driver.findElement(By.id([1])).click(); File file = new File([2]); new WebDriverWait(driver, Duration.ofSeconds(20)).until(d -> file.[3]);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong element id or file path string.
Waiting on isFile() which may be false if file is not fully ready.
✗ Incorrect
Click the element with id "downloadLink", check the file path, and wait until the file exists.