0
0
Selenium Pythontesting~10 mins

Element locators 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 locate the username input field by its ID.

Selenium Python
username_input = driver.find_element(By.[1], "username")
Drag options to blanks, or click blank then click option'
Aname
Bid
Cclass_name
Dtag_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.name when the element has an ID.
Using By.class_name which may select multiple elements.
2fill in blank
medium

Complete the code to locate the login button by its CSS selector.

Selenium Python
login_button = driver.find_element(By.[1], ".btn-login")
Drag options to blanks, or click blank then click option'
Axpath
Blink_text
Ccss_selector
Dpartial_link_text
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.xpath when CSS selector is given.
Using By.link_text which is for links only.
3fill in blank
hard

Fix the error in the locator to find the password input by name.

Selenium Python
password_input = driver.find_element(By.[1], "password")
Drag options to blanks, or click blank then click option'
Aname
Bid
Cclass_name
Dtag_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.id when the element has no ID.
Using By.class_name which may not be unique.
4fill in blank
hard

Fill both blanks to create a locator for a submit button with tag 'button' and class 'submit-btn'.

Selenium Python
submit_button = driver.find_element(By.[1], "[2]")
Drag options to blanks, or click blank then click option'
Acss_selector
Bxpath
Cbutton.submit-btn
D//button[contains(@class, 'submit-btn')]
Attempts:
3 left
💡 Hint
Common Mistakes
Using By.css_selector with an XPath string.
Using incorrect XPath syntax.
5fill in blank
hard

Fill all three blanks to create a dictionary of locators for username, password, and login button.

Selenium Python
locators = {
    "username": (By.[1], "username"),
    "password": (By.[2], "password"),
    "login_button": (By.[3], ".btn-login")
}
Drag options to blanks, or click blank then click option'
Aid
Bname
Ccss_selector
Dxpath
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing locator types incorrectly.
Using By.xpath unnecessarily.