Complete the code to import the Selenium WebDriver module.
from selenium import [1]
The Selenium WebDriver module is imported using webdriver. This allows controlling browsers in tests.
Complete the code to create a new Chrome WebDriver instance.
driver = [1].Chrome()The webdriver.Chrome() creates a new Chrome browser instance controlled by Selenium.
Fix the error in the pytest fixture to properly initialize and quit the WebDriver.
@pytest.fixture def driver(): driver = webdriver.Chrome() yield [1] driver.quit()
webdriver instead of the driver instance.driver.quit() which calls quit too early.The fixture yields the driver instance so tests can use it. Then it quits after tests finish.
Fill both blanks to write a test that opens a page and checks its title.
def test_open_page(driver): driver.[1]('https://example.com') assert driver.title [2] 'Example Domain'
click instead of get to open the page.!= in the assertion which would fail the test.The get method opens the URL. The assertion checks if the page title equals the expected string.
Fill all three blanks to create a fixture that sets up Firefox WebDriver with options and yields it.
from selenium.webdriver.firefox.options import Options @pytest.fixture def firefox_driver(): options = Options() options.[1] = True driver = webdriver.Firefox(options=[2]) yield [3] driver.quit()
Setting headless = True runs Firefox without opening a window. The options object is passed to the driver. The driver instance is yielded for tests.