0
0
Selenium Pythontesting~20 mins

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

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