0
0
Selenium Pythontesting~10 mins

Headless mode for CI in Selenium Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to run Chrome in headless mode.

Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument([1])
driver = webdriver.Chrome(options=options)
driver.get('https://example.com')
driver.quit()
Drag options to blanks, or click blank then click option'
A"--start-maximized"
B"--incognito"
C"--headless"
D"--disable-extensions"
Attempts:
3 left
💡 Hint
Common Mistakes
Using options that don't enable headless mode like incognito or maximized window.
Forgetting to add the argument to options.
2fill in blank
medium

Complete the code to set up Firefox in headless mode.

Selenium Python
from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.[1] = True
driver = webdriver.Firefox(options=options)
driver.get('https://example.com')
driver.quit()
Drag options to blanks, or click blank then click option'
Aincognito
Bheadless
Cmaximize_window
Ddisable_extensions
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect property names like incognito or maximize_window.
Setting the property to a string instead of a boolean.
3fill in blank
hard

Fix the error in the code to correctly run Chrome headless in CI.

Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument([1])
driver = webdriver.Chrome(options=options)
driver.get('https://example.com')
driver.quit()
Drag options to blanks, or click blank then click option'
A"--headless"
B"--disable-gpu"
C"--no-sandbox"
D"--window-size=1920,1080"
Attempts:
3 left
💡 Hint
Common Mistakes
Not passing the options object to the Chrome driver constructor.
Using other arguments that don't enable headless mode.
4fill in blank
hard

Fill both blanks to create a headless Chrome driver with window size set for CI.

Selenium Python
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument([1])
options.add_argument([2])
driver = webdriver.Chrome(options=options)
driver.get('https://example.com')
driver.quit()
Drag options to blanks, or click blank then click option'
A"--headless"
B"--disable-gpu"
C"--window-size=1920,1080"
D"--incognito"
Attempts:
3 left
💡 Hint
Common Mistakes
Using --disable-gpu instead of window size for layout.
Forgetting to add both arguments.
5fill in blank
hard

Fill all three blanks to create a Firefox headless driver with custom user agent and window size for CI.

Selenium Python
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile

options = Options()
options.[1] = True
profile = FirefoxProfile()
profile.set_preference('general.useragent.override', [2])
driver = webdriver.Firefox(options=options, firefox_profile=profile)
driver.set_window_size([3], 1080)
driver.get('https://example.com')
driver.quit()
Drag options to blanks, or click blank then click option'
Aheadless
B"Mozilla/5.0 (CI Testing)"
C1920
D"--headless"
Attempts:
3 left
💡 Hint
Common Mistakes
Using string "--headless" instead of boolean True for headless property.
Passing user agent without quotes or as a variable.
Setting window size width as a string instead of integer.