0
0
Selenium Pythontesting~20 mins

Finding multiple elements in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Multiple Elements Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1: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))
A0
B1
C3
DTypeError
Attempts:
2 left
💡 Hint
Remember that find_elements returns a list of matching elements.
assertion
intermediate
1: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')
Aassert divs.length == 5
Bassert len(divs) == 5
Cassert divs.count == 5
Dassert divs.size() == 5
Attempts:
2 left
💡 Hint
Check how to get the number of items in a Python list.
locator
advanced
2: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?
Adriver.find_elements(By.CSS_SELECTOR, '.item')
Bdriver.find_elements(By.CLASS_NAME, 'item')
Cdriver.find_elements(By.ID, 'item')
Ddriver.find_elements(By.TAG_NAME, 'item')
Attempts:
2 left
💡 Hint
Consider which locator is most flexible and recommended for classes.
🔧 Debug
advanced
2: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))
Afind_elements returns None if no elements found
BThe CSS selector '.active-item' is invalid syntax
CThe driver session has expired
DThe elements are inside an iframe and driver did not switch to it
Attempts:
2 left
💡 Hint
Think about page frames and how Selenium accesses elements inside them.
framework
expert
3: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?
AWebDriverWait(driver, 10).until(lambda d: len(d.find_elements(By.CLASS_NAME, 'notification')) >= 2)
BWebDriverWait(driver, 10).until(lambda d: d.find_element(By.CLASS_NAME, 'notification'))
C
time.sleep(10)
assert len(driver.find_elements(By.CLASS_NAME, 'notification')) &gt;= 2
D
driver.implicitly_wait(10)
assert len(driver.find_elements(By.CLASS_NAME, 'notification')) &gt;= 2
Attempts:
2 left
💡 Hint
Use explicit waits with conditions on element counts.