Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a headless Chrome browser instance.
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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using arguments unrelated to headless mode like "--disable-gpu" or "--incognito".
Not adding any argument and expecting headless mode.
✗ Incorrect
Adding the "--headless" argument tells Chrome to run without opening a visible window.
2fill in blank
mediumComplete the code to set up Firefox in headless mode using Selenium.
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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated properties like 'fullscreen' or 'incognito'.
Setting the property to a string instead of a boolean.
✗ Incorrect
Setting options.headless = True enables Firefox to run without a GUI.
3fill in blank
hardFix the error in the code to correctly 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Not passing options to webdriver.Chrome() causes headless mode to be ignored.
Using wrong arguments that don't enable headless mode.
✗ Incorrect
The code misses passing the options to Chrome driver. Adding the headless argument is correct, but options must be passed to webdriver.Chrome(options=options).
4fill in blank
hardFill both blanks to create a headless Chrome driver with disabled GPU.
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'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to disable GPU can cause rendering problems in headless mode.
Using unrelated arguments like "--incognito".
✗ Incorrect
Headless mode requires "--headless" argument. Disabling GPU with "--disable-gpu" helps avoid some rendering issues in headless mode.
5fill in blank
hardFill all three blanks to create a Firefox headless driver, navigate to a page, and quit.
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([2]) driver.[3]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not setting headless to True causes the browser to open visibly.
Using incorrect method to close the browser like 'close' instead of 'quit'.
Passing URL without quotes causes syntax errors.
✗ Incorrect
Set options.headless = True to run Firefox headless, navigate to the URL string, then call driver.quit() to close the browser.