Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Selenium WebDriver module.
Selenium Python
from selenium import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'driver' or 'browser' instead of 'webdriver' causes import errors.
✗ Incorrect
The correct import to use Selenium WebDriver is webdriver.
2fill in blank
mediumComplete the code to create a Chrome WebDriver instance for running tests.
Selenium Python
driver = [1].Chrome() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'selenium.Chrome()' or 'driver.Chrome()' causes errors.
✗ Incorrect
You create a Chrome browser instance using webdriver.Chrome().
3fill in blank
hardFix the error in the code to run Chrome in headless mode in CI.
Selenium Python
options = webdriver.ChromeOptions()
options.add_argument([1])
driver = webdriver.Chrome(options=options) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Missing dashes or adding '=true' causes Chrome to ignore headless mode.
✗ Incorrect
The correct argument to run Chrome headless is '--headless'.
4fill in blank
hardFill both blanks to add arguments for running Chrome in CI with no sandbox and headless.
Selenium Python
options = webdriver.ChromeOptions() options.add_argument([1]) options.add_argument([2]) driver = webdriver.Chrome(options=options)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '--disable-gpu' or '--incognito' instead of required arguments.
✗ Incorrect
In CI, Chrome often needs --no-sandbox and --headless arguments to run properly.
5fill in blank
hardFill all three blanks to create a dictionary comprehension filtering environment variables for CI setup.
Selenium Python
ci_env = [1]: [2] for [3] in env_vars if [3].startswith('CI_')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing variable names or using undefined names causes errors.
✗ Incorrect
This comprehension creates a dictionary of keys and values where keys start with 'CI_'.