0
0
Selenium Pythontesting~10 mins

Action methods in page class in Selenium Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Atext
Bsend_keys
Cclear
Dclick
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
2fill in blank
medium

Complete 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'
Asend_keys
Bsubmit
Cclear
Dclick
Attempts:
3 left
💡 Hint
Common Mistakes
Using click instead of send_keys to enter text
Forgetting to clear the input before typing
3fill in blank
hard

Fix 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'
Aclick
Bclear
Csubmit
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using click instead of clear to remove text
Trying to assign text property directly
4fill in blank
hard

Fill 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'
Ais_selected
Bclick
Cis_displayed
Dclear
Attempts:
3 left
💡 Hint
Common Mistakes
Using is_displayed instead of is_selected
Using clear instead of click to select checkbox
5fill in blank
hard

Fill 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'
A"email"
B"password"
C"submit-btn"
D"login"
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the IDs for email and password fields
Using incorrect ID for the submit button