Challenge - 5 Problems
Multiple Elements Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
Output of finding multiple elements with Selenium
What will be the output of the following Selenium Python code snippet when the page contains exactly 3 <button> elements?
Selenium Python
buttons = driver.find_elements(By.TAG_NAME, 'button') print(len(buttons))
Attempts:
2 left
💡 Hint
Remember that find_elements returns a list of matching elements.
✗ Incorrect
The method find_elements returns a list of all matching elements. Since there are 3 button elements, len(buttons) will be 3.
❓ assertion
intermediate1:30remaining
Correct assertion for multiple elements count
Which assertion correctly verifies that a page has exactly 5 <div> elements using Selenium Python?
Selenium Python
divs = driver.find_elements(By.TAG_NAME, 'div')Attempts:
2 left
💡 Hint
Check how to get the number of items in a Python list.
✗ Incorrect
In Python, len() returns the number of items in a list. The other options use invalid attributes or methods.
❓ locator
advanced2:00remaining
Best locator to find multiple elements with a specific class
You want to find all elements with the class name 'item' on a page. Which locator is the best practice in Selenium Python?
Attempts:
2 left
💡 Hint
Consider which locator is most flexible and recommended for classes.
✗ Incorrect
Using CSS_SELECTOR with '.item' is the best practice for finding multiple elements by class. CLASS_NAME works but can fail if the class name contains spaces. ID and TAG_NAME are incorrect here.
🔧 Debug
advanced2:00remaining
Debugging find_elements returning empty list
You run the code below but find_elements returns an empty list even though the page has matching elements. What is the most likely cause?
Selenium Python
elements = driver.find_elements(By.CSS_SELECTOR, '.active-item') print(len(elements))
Attempts:
2 left
💡 Hint
Think about page frames and how Selenium accesses elements inside them.
✗ Incorrect
If elements are inside an iframe, Selenium cannot find them unless you switch to that iframe first. The CSS selector is valid, find_elements returns an empty list (not None), and driver session expiration would cause errors.
❓ framework
expert3:00remaining
Handling dynamic multiple elements in test framework
In a test framework using Selenium Python, you want to wait until at least 2 elements with class 'notification' appear before continuing. Which approach correctly implements this wait?
Attempts:
2 left
💡 Hint
Use explicit waits with conditions on element counts.
✗ Incorrect
Option A uses explicit wait with a lambda checking the count of elements, which is the correct way to wait for multiple elements. Option A waits only for one element. Option A uses fixed sleep which is unreliable. Option A uses implicit wait which does not wait for element count.