Consider the following Selenium code that sets a Firefox profile preference and then retrieves it. What will be printed?
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()
Check how to access preferences from the FirefoxProfile object after setting them.
The default_preferences attribute does not reflect the updated preferences set by set_preference. Therefore, get returns None.
You want to check that the Firefox profile has the homepage set to https://example.com. Which assertion is correct?
from selenium import webdriver profile = webdriver.FirefoxProfile() profile.set_preference('browser.startup.homepage', 'https://example.com') # Which assertion below is correct?
Look inside the FirefoxProfile object to find where preferences are stored.
The _preferences dictionary holds the preferences set by set_preference. Using get avoids KeyError if missing.
The test sets a custom homepage but Firefox opens with the default page. Identify the bug.
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.
Think about what driver.get('about:home') does after browser starts.
Calling driver.get('about:home') navigates explicitly to Firefox's default home page, ignoring the profile's homepage setting.
Which code snippet correctly applies a Firefox profile using Selenium's recommended approach?
Check how to assign profile to options in Selenium 4+.
In Selenium 4+, the FirefoxProfile should be assigned to options.profile before passing options to the driver constructor.
Why do testers use browser profiles when running automated Selenium tests?
Think about controlling browser behavior and environment.
Browser profiles allow setting preferences, extensions, and other configurations to ensure tests run in a controlled, repeatable environment.