Bird
Raised Fist0
Selenium Pythontesting~20 mins

Browser profile configuration in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Browser Profile 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 Python code snippet?

Consider the following Selenium code that sets a Firefox profile preference and then retrieves it. What will be printed?

Selenium Python
from selenium import webdriver
from selenium.webdriver.firefox.options import Options

profile = webdriver.FirefoxProfile()
profile.set_preference('browser.startup.homepage', 'https://example.com')
profile.update_preferences()

options = Options()
driver = webdriver.Firefox(firefox_profile=profile, options=options)

homepage = profile._preferences.get('browser.startup.homepage')
print(homepage)
driver.quit()
Ahttps://example.com
BSyntaxError
CKeyError exception
DNone
Attempts:
2 left
💡 Hint

Check how to access preferences from the FirefoxProfile object after setting them.

❓ assertion
intermediate
2:00remaining
Which assertion correctly verifies the browser profile preference was set?

You want to check that the Firefox profile has the homepage set to https://example.com. Which assertion is correct?

Selenium Python
from selenium import webdriver

profile = webdriver.FirefoxProfile()
profile.set_preference('browser.startup.homepage', 'https://example.com')

# Which assertion below is correct?
Aassert profile.default_preferences['browser.startup.homepage'] == 'https://example.com'
Bassert profile._preferences['browser.startup.homepage'] == 'https://example.com'
Cassert profile.get_preference('browser.startup.homepage') == 'https://example.com'
Dassert profile._preferences.get('browser.startup.homepage') == 'https://example.com'
Attempts:
2 left
💡 Hint

Look inside the FirefoxProfile object to find where preferences are stored.

🔧 Debug
advanced
2:00remaining
Why does this Selenium Firefox profile code fail to load the custom homepage?

The test sets a custom homepage but Firefox opens with the default page. Identify the bug.

Selenium Python
from selenium import webdriver

profile = webdriver.FirefoxProfile()
profile.set_preference('browser.startup.homepage', 'https://custompage.com')

driver = webdriver.Firefox(firefox_profile=profile)
# driver.get('about:home')  # This line causes the homepage override

# Expected homepage is https://custompage.com but it opens default Firefox page.
AMissing call to profile.update_preferences() before creating driver
BCalling driver.get('about:home') overrides homepage setting
CUsing deprecated firefox_profile argument instead of options
DHomepage preference key is incorrect
Attempts:
2 left
💡 Hint

Think about what driver.get('about:home') does after browser starts.

❓ framework
advanced
2:00remaining
How to correctly apply a Firefox profile in Selenium with modern options?

Which code snippet correctly applies a Firefox profile using Selenium's recommended approach?

A
profile = webdriver.FirefoxProfile()
profile.set_preference('key', 'value')
options = webdriver.FirefoxOptions()
options.profile = profile
driver = webdriver.Firefox(options=options)
B
profile = webdriver.FirefoxProfile()
profile.set_preference('key', 'value')
driver = webdriver.Firefox(firefox_profile=profile)
C
options = webdriver.FirefoxOptions()
options.set_preference('key', 'value')
driver = webdriver.Firefox(options=options)
D
profile = webdriver.FirefoxProfile()
profile.set_preference('key', 'value')
options = webdriver.FirefoxOptions()
driver = webdriver.Firefox(firefox_profile=profile, options=options)
Attempts:
2 left
💡 Hint

Check how to assign profile to options in Selenium 4+.

🧠 Conceptual
expert
2:00remaining
What is the main advantage of using a browser profile in automated tests?

Why do testers use browser profiles when running automated Selenium tests?

ATo avoid writing test assertions by preloading test data
BTo speed up test execution by disabling all browser features
CTo customize browser settings and extensions for consistent test environments
DTo automatically generate test reports after each test run
Attempts:
2 left
💡 Hint

Think about controlling browser behavior and environment.

Practice

(1/5)
1. What is the main purpose of configuring a browser profile in Selenium tests?
easy
A. To write test cases faster
B. To customize browser settings before running tests
C. To increase the speed of Selenium WebDriver
D. To change the programming language of the test

Solution

  1. Step 1: Understand browser profile role

    A browser profile allows setting preferences like homepage, notifications, or extensions before tests run.
  2. Step 2: Identify the main purpose

    This customization helps simulate different user environments during testing.
  3. Final Answer:

    To customize browser settings before running tests -> Option B
  4. Quick Check:

    Browser profile = Customize settings [OK]
Hint: Browser profile changes browser setup before tests [OK]
Common Mistakes:
  • Thinking it speeds up test execution
  • Confusing profile with test case writing
  • Believing it changes test language
2. Which of the following is the correct way to set a Firefox browser preference for disabling notifications using Selenium in Python?
easy
A. profile.set_preference('dom.webnotifications.enabled', False)
B. profile.setPreference('dom.webnotifications.enabled', 'false')
C. profile.set_preference('dom.webnotifications.enabled', 'False')
D. profile.set_preference('dom.webnotifications.enabled', 0)

Solution

  1. Step 1: Check method name and argument types

    The correct method is set_preference with lowercase 'p' and boolean False (not string).
  2. Step 2: Validate option values

    profile.set_preference('dom.webnotifications.enabled', False) uses correct method and boolean False, which disables notifications properly.
  3. Final Answer:

    profile.set_preference('dom.webnotifications.enabled', False) -> Option A
  4. Quick Check:

    Correct method + boolean False = profile.set_preference('dom.webnotifications.enabled', False) [OK]
Hint: Use set_preference with exact method name and boolean values [OK]
Common Mistakes:
  • Using wrong method name like setPreference
  • Passing boolean as string 'False'
  • Using integer 0 instead of boolean False
3. 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?
medium
A. https://example.com
B. None
C. KeyError
D. about:blank

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]
Hint: 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
4. You wrote this code to disable Firefox notifications but it still shows notifications during tests:
profile = FirefoxProfile()
profile.set_preference('dom.webnotifications.enabled', 'false')
profile.update_preferences()
What is the likely cause of this problem?
medium
A. The method update_preferences() is deprecated and should be removed
B. Missing call to profile.save() before using profile
C. Notifications cannot be disabled via profile settings
D. The preference value should be boolean False, not string 'false'

Solution

  1. Step 1: Check preference value type

    The value 'false' is a string, but the preference expects a boolean False to disable notifications.
  2. Step 2: Understand effect of wrong type

    Passing string 'false' does not disable notifications, so they still appear.
  3. Final Answer:

    The preference value should be boolean False, not string 'false' -> Option D
  4. Quick Check:

    Boolean False needed, not string 'false' [OK]
Hint: Use boolean False, not string, to disable prefs [OK]
Common Mistakes:
  • Using string 'false' instead of boolean False
  • Thinking update_preferences() is deprecated
  • Believing notifications can't be disabled
5. You want to test your website's behavior when the browser homepage is set to 'https://testsite.com' and notifications are disabled. Which code snippet correctly configures the Firefox profile and launches the browser with these settings?
hard
A. profile = FirefoxProfile() profile.set_preference('browser.startup.homepage', 'https://testsite.com') profile.set_preference('dom.webnotifications.enabled', False) profile.update_preferences() driver = webdriver.Firefox(firefox_profile=profile)
B. profile = FirefoxProfile() profile.set_preference('browser.startup.homepage', 'https://testsite.com') profile.set_preference('dom.webnotifications.enabled', 'False') driver = webdriver.Firefox(profile)
C. profile = FirefoxProfile() profile.set_preference('browser.startup.homepage', 'https://testsite.com') profile.set_preference('dom.webnotifications.enabled', False) driver = webdriver.Firefox(profile=profile)
D. profile = FirefoxProfile() profile.set_preference('browser.startup.homepage', 'https://testsite.com') profile.set_preference('dom.webnotifications.enabled', False) profile.update_preferences() driver = webdriver.Firefox(profile)

Solution

  1. Step 1: Set preferences correctly

    Use set_preference with correct keys and boolean False for notifications.
  2. Step 2: Update preferences and pass profile correctly

    Call update_preferences() and pass profile as firefox_profile=profile to WebDriver.
  3. Final Answer:

    Code snippet in Option A correctly sets preferences, updates them, and launches Firefox with profile -> Option A
  4. Quick Check:

    Set prefs + update + firefox_profile param = profile = FirefoxProfile() profile.set_preference('browser.startup.homepage', 'https://testsite.com') profile.set_preference('dom.webnotifications.enabled', False) profile.update_preferences() driver = webdriver.Firefox(firefox_profile=profile) [OK]
Hint: Call update_preferences() and pass firefox_profile param [OK]
Common Mistakes:
  • Passing profile without keyword argument
  • Using string 'False' instead of boolean False
  • Forgetting update_preferences() call
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard