0
0
Selenium Pythontesting~20 mins

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

Choose your learning style9 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.