0
0
Selenium Pythontesting~10 mins

Find element by ID 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 find an element by its ID using Selenium in Python.

Selenium Python
element = 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 'name' or 'class_name' instead of 'id' when looking for an element by ID.
2fill in blank
medium

Complete the code to click on an element found by its ID.

Selenium Python
driver.find_element_by_[1]("submit-btn").click()
Drag options to blanks, or click blank then click option'
Aid
Bclass_name
Cname
Dtag_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong attribute in the find_element method.
3fill in blank
hard

Fix the error in the code to correctly find an element by ID.

Selenium Python
element = driver.find_element_by_[1]("password")
Drag options to blanks, or click blank then click option'
Aclass_name
Bname
Cid
Dtag_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using find_element instead of find_element_by_id.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that finds elements by ID and stores their text.

Selenium Python
texts = {id: driver.find_element_by_[1](id).text for id in ids if id [2] ""}
Drag options to blanks, or click blank then click option'
Aid
B!=
C==
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '!=' in the condition.
Using 'name' instead of 'id' in the method.
5fill in blank
hard

Fill all three blanks to create a test that asserts an element with a specific ID is displayed.

Selenium Python
element = driver.find_element_by_[1]("login-button")
assert element.is_[2](), "Element not visible"
print("Element with ID [3] is visible")
Drag options to blanks, or click blank then click option'
Aid
Bdisplayed
Clogin-button
Denabled
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'enabled' instead of 'displayed' for visibility check.
Mismatching the printed ID string.