Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define an action method that clicks a button.
Selenium Python
def click_submit(self): self.driver.find_element(By.ID, 'submit').[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using send_keys instead of click for clicking a button
Trying to access text property instead of calling a method
✗ Incorrect
The click() method simulates a mouse click on the button element.
2fill in blank
mediumComplete the code to enter text into a search input field.
Selenium Python
def enter_search_text(self, text): search_box = self.driver.find_element(By.NAME, 'q') search_box.[1](text)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using click instead of send_keys to enter text
Forgetting to clear the input before typing
✗ Incorrect
The send_keys() method types the given text into the input field.
3fill in blank
hardFix the error in the method that clears and types text into an input field.
Selenium Python
def update_username(self, username): input_field = self.driver.find_element(By.ID, 'username') input_field.[1]() input_field.send_keys(username)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using click instead of clear to remove text
Trying to assign text property directly
✗ Incorrect
The clear() method removes any existing text before typing new text.
4fill in blank
hardFill both blanks to create a method that selects a checkbox if it is not already selected.
Selenium Python
def select_checkbox(self): checkbox = self.driver.find_element(By.CSS_SELECTOR, '#agree') if not checkbox.[1]: checkbox.[2]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using is_displayed instead of is_selected
Using clear instead of click to select checkbox
✗ Incorrect
is_selected checks if the checkbox is checked. If not, click() selects it.
5fill in blank
hardFill all three blanks to define a method that submits a form after entering email and password.
Selenium Python
def login(self, email, password): self.driver.find_element(By.ID, [1]).send_keys(email) self.driver.find_element(By.ID, [2]).send_keys(password) self.driver.find_element(By.ID, [3]).click()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the IDs for email and password fields
Using incorrect ID for the submit button
✗ Incorrect
The method fills the email and password fields by their IDs and clicks the submit button.