Bird
Raised Fist0
Selenium Pythontesting~20 mins

Browser options and capabilities in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Browser Options 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 Selenium browser options code?
Consider the following Python Selenium code snippet that sets Chrome options. What will be printed when the code runs?
Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
driver = webdriver.Chrome(options=options)
print(driver.capabilities.get('headless'))
driver.quit()
ANone
BTrue
CKeyError
DFalse
Attempts:
2 left
💡 Hint
Check how the headless argument affects the capabilities dictionary.
❓ assertion
intermediate
2:00remaining
Which assertion correctly verifies the browser is running in incognito mode?
You want to check if Chrome is running in incognito mode using Selenium Python. Which assertion correctly verifies this?
Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--incognito')
driver = webdriver.Chrome(options=options)

# Which assertion below is correct?
Aassert '--incognito' in driver.capabilities['goog:chromeOptions']['args']
Bassert 'incognito' in driver.capabilities['browserName']
Cassert driver.capabilities['incognito'] == True
Dassert driver.capabilities['chromeOptions']['incognito'] is not None
Attempts:
2 left
💡 Hint
Check where Chrome options arguments are stored in capabilities.
🔧 Debug
advanced
2:00remaining
Why does this Selenium code fail to set the user agent?
The following code tries to set a custom user agent in Chrome but it does not work. What is the reason?
Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('user-agent=MyCustomAgent/1.0')
driver = webdriver.Chrome(options=options)
print(driver.execute_script('return navigator.userAgent;'))
driver.quit()
AMissing double dashes before 'user-agent' argument; should be '--user-agent=MyCustomAgent/1.0'
BUser agent cannot be set via Chrome options; must use capabilities instead
CThe argument should be passed as options.set_capability('userAgent', 'MyCustomAgent/1.0')
DThe user agent string is ignored if headless mode is not enabled
Attempts:
2 left
💡 Hint
Check the syntax of Chrome command line arguments.
🧠 Conceptual
advanced
1:30remaining
What is the main purpose of browser capabilities in Selenium?
Choose the best description of the main purpose of browser capabilities in Selenium WebDriver.
ATo store test results and logs during test execution
BTo define the test case steps and assertions
CTo specify browser-specific settings and features before launching the browser
DTo manage network traffic and proxy settings only
Attempts:
2 left
💡 Hint
Think about what capabilities configure before the browser starts.
❓ framework
expert
3:00remaining
How to correctly combine Chrome options and capabilities in Selenium Python?
You want to run Chrome in headless mode and set a proxy using Selenium Python. Which code snippet correctly combines Chrome options and capabilities?
A
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--proxy-server=http://proxy.example.com:8080')
driver = webdriver.Chrome(options=options)
B
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
capabilities = webdriver.DesiredCapabilities.CHROME.copy()
capabilities['proxy'] = {'proxyType': 'manual', 'httpProxy': 'proxy.example.com:8080'}
driver = webdriver.Chrome(options=options, desired_capabilities=capabilities)
C
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
capabilities = webdriver.DesiredCapabilities.CHROME.copy()
capabilities['proxy'] = {'proxyType': 'manual', 'httpProxy': 'proxy.example.com:8080'}
driver = webdriver.Chrome(desired_capabilities=capabilities)
D
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.set_capability('proxy', {'proxyType': 'manual', 'httpProxy': 'proxy.example.com:8080'})
driver = webdriver.Chrome(options=options)
Attempts:
2 left
💡 Hint
Check how to set proxy with Chrome options in Selenium Python 4+.

Practice

(1/5)
1. What is the main purpose of using Options in Selenium WebDriver for browsers?
easy
A. To customize browser settings like headless mode or window size
B. To write test assertions for page elements
C. To locate elements on a web page
D. To generate test reports automatically

Solution

  1. Step 1: Understand what Options configure

    Options allow you to set how the browser behaves during tests, such as running headless or setting window size.
  2. Step 2: Differentiate Options from other tasks

    Options do not handle locating elements, assertions, or reports; those are separate tasks.
  3. Final Answer:

    To customize browser settings like headless mode or window size -> Option A
  4. Quick Check:

    Options = Browser customization [OK]
Hint: Options control browser behavior, not test logic [OK]
Common Mistakes:
  • Confusing Options with element locators
  • Thinking Options generate reports
  • Mixing Options with assertion logic
2. Which of the following is the correct way to set Chrome to run in headless mode using Selenium in Python?
easy
A. options = webdriver.ChromeOptions() options.add_argument('--headless')
B. options = webdriver.ChromeOptions() options.set_headless(True)
C. options = webdriver.ChromeOptions() options.headless = True
D. options = webdriver.ChromeOptions() options.add_option('headless')

Solution

  1. Step 1: Recall correct method to add arguments

    In Selenium Python, add_argument is used to add command line switches like '--headless'.
  2. Step 2: Check each option's syntax

    Only options = webdriver.ChromeOptions() options.add_argument('--headless') uses add_argument('--headless') correctly; others use invalid or non-existent methods.
  3. Final Answer:

    options = webdriver.ChromeOptions() options.add_argument('--headless') -> Option A
  4. Quick Check:

    Use add_argument('--headless') for headless mode [OK]
Hint: Use add_argument('--headless') to enable headless mode [OK]
Common Mistakes:
  • Using non-existent set_headless method
  • Assigning headless attribute directly
  • Using add_option instead of add_argument
3. What will be the effect of the following Python Selenium code snippet?
from selenium import webdriver
options = webdriver.FirefoxOptions()
options.set_preference('dom.webnotifications.enabled', False)
driver = webdriver.Firefox(options=options)
driver.get('https://example.com')
medium
A. Code will raise an error due to invalid method
B. Firefox will launch but notifications will still appear
C. Firefox will launch with notifications disabled on the page
D. Firefox will launch in headless mode

Solution

  1. Step 1: Understand set_preference usage

    The method set_preference sets Firefox preferences; here it disables web notifications.
  2. Step 2: Analyze the effect on browser behavior

    Passing these options to Firefox disables notifications on pages, so no pop-ups appear.
  3. Final Answer:

    Firefox will launch with notifications disabled on the page -> Option C
  4. Quick Check:

    set_preference disables notifications [OK]
Hint: set_preference disables features like notifications [OK]
Common Mistakes:
  • Assuming notifications still appear
  • Confusing set_preference with add_argument
  • Thinking code runs headless by default
4. Identify the error in this Selenium Python code snippet that tries to disable browser notifications in Chrome:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.set_preference('profile.default_content_setting_values.notifications', 2)
driver = webdriver.Chrome(options=options)
medium
A. The value 2 is invalid for disabling notifications
B. set_preference is not a method of ChromeOptions
C. Options must be passed as capabilities, not options
D. ChromeOptions cannot disable notifications

Solution

  1. Step 1: Check ChromeOptions methods

    ChromeOptions does not have a method called set_preference; this is Firefox-specific.
  2. Step 2: Correct way to disable notifications in Chrome

    Chrome uses add_experimental_option with 'prefs' dictionary to disable notifications.
  3. Final Answer:

    set_preference is not a method of ChromeOptions -> Option B
  4. Quick Check:

    Use add_experimental_option for Chrome prefs [OK]
Hint: ChromeOptions uses add_experimental_option, not set_preference [OK]
Common Mistakes:
  • Using Firefox methods on ChromeOptions
  • Passing wrong values for notification settings
  • Confusing options with capabilities
5. You want to run Chrome in headless mode, disable notifications, and accept insecure certificates using Selenium in Python. Which code snippet correctly sets all these options?
hard
A. options = webdriver.ChromeOptions() options.headless = True options.add_experimental_option('prefs', {'notifications': 0}) options.set_capability('acceptInsecureCerts', False) driver = webdriver.Chrome(options=options)
B. options = webdriver.ChromeOptions() options.add_argument('headless') options.set_preference('notifications', False) options.set_capability('acceptInsecureCerts', True) driver = webdriver.Chrome(options=options)
C. options = webdriver.ChromeOptions() options.add_argument('--headless') options.add_argument('--disable-notifications') options.accept_insecure_certs = True driver = webdriver.Chrome(options=options)
D. options = webdriver.ChromeOptions() options.add_argument('--headless') options.add_experimental_option('prefs', {'profile.default_content_setting_values.notifications': 2}) options.set_capability('acceptInsecureCerts', True) driver = webdriver.Chrome(options=options)

Solution

  1. Step 1: Set headless mode correctly

    Use add_argument('--headless') to enable headless mode in ChromeOptions.
  2. Step 2: Disable notifications properly

    Use add_experimental_option('prefs', {'profile.default_content_setting_values.notifications': 2}) to disable notifications.
  3. Step 3: Accept insecure certificates

    Set capability acceptInsecureCerts to True using set_capability.
  4. Final Answer:

    options = webdriver.ChromeOptions() options.add_argument('--headless') options.add_experimental_option('prefs', {'profile.default_content_setting_values.notifications': 2}) options.set_capability('acceptInsecureCerts', True) driver = webdriver.Chrome(options=options) -> Option D
  5. Quick Check:

    Combine add_argument, add_experimental_option, set_capability [OK]
Hint: Use add_argument, add_experimental_option, set_capability together [OK]
Common Mistakes:
  • Missing '--' in headless argument
  • Using set_preference on ChromeOptions
  • Setting acceptInsecureCerts to False by mistake
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