Complete the code to define a page object class for a login page.
class LoginPage: def __init__(self, driver): self.driver = driver self.username_field = self.driver.find_element_by_id([1])
The username field is identified by the id "username" in the page object.
Complete the method to enter text into the username field.
def enter_username(self, username): self.username_field.[1](username)
To type text into a field, we use the send_keys method.
Fix the error in the method to click the login button.
def click_login(self): self.driver.find_element_by_id([1]).click()
The login button is identified by the id "submit" in this example.
Fill both blanks to create a method that logs in with username and password.
def login(self, username, password): self.username_field.[1](username) self.password_field.[2](password)
Both username and password fields require send_keys to enter text.
Fill all three blanks to define a complete login page object with methods to enter username, password, and click login.
class LoginPage: def __init__(self, driver): self.driver = driver self.username_field = self.driver.find_element_by_id([1]) self.password_field = self.driver.find_element_by_id([2]) self.login_button = self.driver.find_element_by_id([3]) def enter_username(self, username): self.username_field.send_keys(username) def enter_password(self, password): self.password_field.send_keys(password) def click_login(self): self.login_button.click()
The username, password, and login button are identified by ids "username", "password", and "submit" respectively.
