Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a page object class for a login page.
Testing Fundamentals
class LoginPage: def __init__(self, driver): self.driver = driver self.username_field = self.driver.find_element_by_id([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the password or submit button id instead of username.
✗ Incorrect
The username field is identified by the id "username" in the page object.
2fill in blank
mediumComplete the method to enter text into the username field.
Testing Fundamentals
def enter_username(self, username): self.username_field.[1](username)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using click or submit instead of send_keys.
✗ Incorrect
To type text into a field, we use the send_keys method.
3fill in blank
hardFix the error in the method to click the login button.
Testing Fundamentals
def click_login(self): self.driver.find_element_by_id([1]).click()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect id names like 'login' or 'login_button'.
✗ Incorrect
The login button is identified by the id "submit" in this example.
4fill in blank
hardFill both blanks to create a method that logs in with username and password.
Testing Fundamentals
def login(self, username, password): self.username_field.[1](username) self.password_field.[2](password)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using click or submit instead of send_keys for input fields.
✗ Incorrect
Both username and password fields require send_keys to enter text.
5fill in blank
hardFill all three blanks to define a complete login page object with methods to enter username, password, and click login.
Testing Fundamentals
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()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up ids or using wrong element ids.
✗ Incorrect
The username, password, and login button are identified by ids "username", "password", and "submit" respectively.