Complete the code to import the Selenium WebDriver module.
from selenium import [1]
The Selenium WebDriver module is imported using webdriver. This allows controlling the browser.
Complete the code to define a Page Object class for the login page.
class LoginPage: def __init__(self, driver): self.driver = [1]
The constructor stores the WebDriver instance in self.driver to use it in page methods.
Fix the error in the method that clicks the login button using a locator.
def click_login(self): login_button = self.driver.find_element_by_[1]("loginBtn") login_button.click()
The method find_element_by_id locates elements by their id attribute, which is correct here.
Fill both blanks to create a method that enters username and password.
def login(self, username, password): self.driver.find_element_by_[1]("username").send_keys(username) self.driver.find_element_by_[2]("password").send_keys(password)
Using find_element_by_id for both username and password fields is common when their HTML elements have id attributes.
Fill the two blanks to write a test that uses the LoginPage object to perform login and verify success.
def test_login(): driver = webdriver.Chrome() login_page = LoginPage(driver) driver.get("http://example.com/login") login_page.login([1], [2]) login_page.click_login() assert "Dashboard" in driver.title driver.quit()
The test calls login with username "user1" and password "pass123". The assertion checks if "Dashboard" is in the page title after login.