Bird
Raised Fist0
Selenium Pythontesting~20 mins

Firefox configuration in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Firefox Configuration Master
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 Firefox profile configuration code?
Consider the following Selenium Python code that sets a Firefox profile preference. What will be the value of the preference browser.startup.homepage after running this code?
Selenium Python
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile

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

options = Options()
options.profile = profile

print(profile.default_preferences.get('browser.startup.homepage'))
Ahttps://example.com
BNone
C'' (empty string)
DRaises AttributeError
Attempts:
2 left
💡 Hint
Check how preferences are set and accessed in FirefoxProfile.
❓ assertion
intermediate
1:30remaining
Which assertion correctly verifies Firefox runs in headless mode?
Given a Selenium Firefox WebDriver instance configured to run headless, which assertion correctly checks that the browser is running in headless mode?
Selenium Python
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options

options = Options()
options.headless = True

driver = Firefox(options=options)

# Which assertion below is correct?
Aassert driver.options.headless == False
Bassert driver.options.headless is None
Cassert driver.capabilities['headless'] == 'True'
Dassert driver.capabilities['moz:headless'] is True
Attempts:
2 left
💡 Hint
Check the capabilities dictionary for the 'moz:headless' key.
🔧 Debug
advanced
2:30remaining
Why does this Firefox WebDriver fail to start with a custom profile?
This Selenium Python code tries to start Firefox with a custom profile but raises an error. Identify the cause.
Selenium Python
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile

profile = FirefoxProfile('/path/to/custom/profile')
options = Options()
options.profile = profile

driver = Firefox(options=options)
AThe profile path is invalid or inaccessible causing a FileNotFoundError
BUsing options.profile with FirefoxProfile path causes an error; should use FirefoxProfile directly in Firefox()
CFirefoxProfile cannot be passed to options.profile; must use options.set_preference instead
DMissing geckodriver executable in PATH causes failure
Attempts:
2 left
💡 Hint
Check if the profile path exists and is accessible.
❓ framework
advanced
2:00remaining
How to configure Firefox to accept insecure certificates in Selenium Python?
You want Firefox WebDriver to accept insecure SSL certificates during tests. Which code snippet correctly configures this?
A
options = Options()
options.set_preference('security.insecure_field_warning.contextual.enabled', False)
driver = Firefox(options=options)
B
profile = FirefoxProfile()
profile.set_preference('acceptInsecureCerts', True)
driver = Firefox(firefox_profile=profile)
C
options = Options()
options.accept_insecure_certs = True
 driver = Firefox(options=options)
D
driver = Firefox()
driver.accept_insecure_certs = True
Attempts:
2 left
💡 Hint
Check the Options class for accepting insecure certs.
🧠 Conceptual
expert
1:30remaining
What is the effect of setting 'dom.webnotifications.enabled' to False in Firefox profile?
In Firefox profile preferences, what does setting dom.webnotifications.enabled to False do during automated testing?
ABlocks all JavaScript execution on the page
BDisables web push notifications, preventing pop-ups during tests
CEnables web notifications, allowing tests to receive alerts
DCauses Firefox to run in safe mode
Attempts:
2 left
💡 Hint
Think about how notifications affect test stability.

Practice

(1/5)
1. What is the main purpose of using FirefoxOptions() in Selenium tests?
easy
A. To configure Firefox browser settings before starting the test
B. To write test assertions for Firefox browser
C. To locate elements on a Firefox webpage
D. To generate test reports for Firefox tests

Solution

  1. Step 1: Understand the role of FirefoxOptions

    FirefoxOptions() is used to set browser preferences like headless mode or disable notifications before launching Firefox.
  2. Step 2: Differentiate from other Selenium tasks

    Locating elements, assertions, and reports are separate tasks not handled by FirefoxOptions().
  3. Final Answer:

    To configure Firefox browser settings before starting the test -> Option A
  4. Quick Check:

    FirefoxOptions() = configure browser [OK]
Hint: Options set browser behavior before test starts [OK]
Common Mistakes:
  • Confusing options with element locators
  • Thinking options generate reports
  • Mixing options with assertions
2. Which of the following is the correct way to enable headless mode in Firefox using Selenium Python?
easy
A. options = FirefoxOptions() options.set_headless(True)
B. options = FirefoxOptions() options.add_argument('--headless')
C. options = FirefoxOptions() options.headless = True
D. options = FirefoxOptions() options.enable_headless()

Solution

  1. Step 1: Recall correct syntax for headless mode

    In Selenium Python, options.headless = True is the standard way to enable headless mode for Firefox.
  2. Step 2: Check other options for correctness

    set_headless() and enable_headless() are not valid methods. add_argument('--headless') works for Chrome but not recommended for Firefox.
  3. Final Answer:

    options = FirefoxOptions() options.headless = True -> Option C
  4. Quick Check:

    Set options.headless = True for Firefox headless [OK]
Hint: Use options.headless = True for Firefox headless mode [OK]
Common Mistakes:
  • Using Chrome syntax like add_argument('--headless')
  • Calling non-existent methods like set_headless()
  • Forgetting to create FirefoxOptions instance
3. What will be the output of the following code snippet?
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options

options = Options()
options.headless = True
browser = Firefox(options=options)
print(browser.capabilities['moz:headless'])
browser.quit()
medium
A. KeyError exception
B. True
C. None
D. False

Solution

  1. Step 1: Understand headless option effect on capabilities

    Setting options.headless = True tells Firefox to run without UI, reflected in capabilities under key 'moz:headless' as True.
  2. Step 2: Check the print statement output

    The print statement accesses browser.capabilities['moz:headless'], which will be True because headless mode is enabled.
  3. Final Answer:

    True -> Option B
  4. Quick Check:

    Headless mode enabled means moz:headless = True [OK]
Hint: Check capabilities key 'moz:headless' for headless status [OK]
Common Mistakes:
  • Assuming 'moz:headless' key is missing
  • Expecting False when headless is set True
  • Confusing capabilities with options
4. Identify the error in the following Firefox configuration code and select the fix:
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options

options = Options()
options.headless(True)
browser = Firefox(options=options)
browser.quit()
medium
A. Change options.headless(True) to options.headless = True
B. Import FirefoxOptions instead of Options
C. Add browser.quit() before creating browser
D. Remove options argument from Firefox() constructor

Solution

  1. Step 1: Identify incorrect method call

    The line options.headless(True) incorrectly calls headless as a method, but it is a property to set.
  2. Step 2: Correct syntax for setting headless

    It should be options.headless = True to enable headless mode properly.
  3. Final Answer:

    Change options.headless(True) to options.headless = True -> Option A
  4. Quick Check:

    Set headless as property, not method [OK]
Hint: Use assignment (=), not function call, for headless [OK]
Common Mistakes:
  • Calling headless as a method
  • Confusing Options class import
  • Misplacing browser.quit() call
5. You want to disable Firefox notifications during Selenium tests to avoid pop-ups. Which code snippet correctly sets this preference using FirefoxOptions?
hard
A. options = FirefoxOptions() options.set_capability('notifications', False)
B. options = FirefoxOptions() options.add_argument('--disable-notifications')
C. options = FirefoxOptions() options.headless = False options.disable_notifications = True
D. options = FirefoxOptions() options.set_preference('dom.webnotifications.enabled', False)

Solution

  1. Step 1: Identify correct method to set Firefox preferences

    Use options.set_preference() to set Firefox-specific preferences like disabling notifications.
  2. Step 2: Verify preference key and value

    The key 'dom.webnotifications.enabled' controls notifications; setting it to False disables them.
  3. Final Answer:

    options = FirefoxOptions() options.set_preference('dom.webnotifications.enabled', False) -> Option D
  4. Quick Check:

    Use set_preference with correct key to disable notifications [OK]
Hint: Use set_preference('dom.webnotifications.enabled', False) [OK]
Common Mistakes:
  • Using add_argument for Firefox preferences
  • Setting non-existent properties like disable_notifications
  • Confusing capabilities with preferences
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