Bird
0
0

Consider this Python code snippet configuring a Firefox profile:

medium📝 Predict Output Q13 of 15
Selenium Python - Advanced Patterns
Consider this Python code snippet configuring a Firefox profile:
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
profile = FirefoxProfile()
profile.set_preference('browser.startup.homepage', 'https://example.com')
profile.set_preference('dom.webnotifications.enabled', False)
profile.update_preferences()

print(profile.default_preferences['browser.startup.homepage'])
What will be printed when this code runs?
Ahttps://example.com
BNone
CKeyError
Dabout:blank
Step-by-Step Solution
Solution:
  1. Step 1: Understand FirefoxProfile attributes

    The default_preferences attribute is internal and not updated by set_preference. It may not contain the key.
  2. Step 2: Predict print behavior

    Accessing profile.default_preferences['browser.startup.homepage'] will raise a KeyError because this key is not in default_preferences.
  3. Final Answer:

    KeyError -> Option C
  4. Quick Check:

    Accessing missing key = KeyError [OK]
Quick Trick: Access only updated prefs, not default_preferences dict [OK]
Common Mistakes:
  • Assuming set_preference updates default_preferences
  • Expecting print to show new homepage URL
  • Ignoring that KeyError occurs on missing dict key

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes