Bird
0
0

Identify the error in this code snippet for setting Chrome options to auto-download files:

medium📝 Debug Q6 of 15
Selenium Python - Advanced Patterns
Identify the error in this code snippet for setting Chrome options to auto-download files:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option('prefs', {
  'download.default_directory': '/tmp/downloads',
  'download.prompt_for_download': False
})
driver = webdriver.Chrome(options=options)
ANo error; the code correctly sets Chrome options for downloads
BThe 'download.prompt_for_download' value should be a string 'false', not boolean
CThe path '/tmp/downloads' must be an absolute path
DThe 'prefs' key should be 'preferences'
Step-by-Step Solution
Solution:
  1. Step 1: Review ChromeOptions preferences syntax

    The 'prefs' dictionary keys and values are correctly set with boolean and string types.
  2. Step 2: Validate path and keys

    'download.default_directory' accepts absolute paths; '/tmp/downloads' is absolute on Unix systems.
  3. Final Answer:

    No error; the code correctly sets Chrome options for downloads -> Option A
  4. Quick Check:

    Correct Chrome prefs syntax = no error [OK]
Quick Trick: Use boolean False, not string, for prompt_for_download [OK]
Common Mistakes:
  • Using string 'false' instead of boolean
  • Wrong prefs key name
  • Using relative paths incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes