Bird
Raised Fist0
Selenium Pythontesting~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does the find_elements method in Selenium Python return when used to locate multiple elements?
easy
A. A list of WebElement objects matching the locator
B. A single WebElement object
C. A boolean indicating if elements exist
D. An integer count of elements found

Solution

  1. Step 1: Understand the purpose of find_elements

    This method is designed to find all elements matching a locator, not just one.
  2. Step 2: Identify the return type

    It returns a list of WebElement objects, even if the list is empty when no elements match.
  3. Final Answer:

    A list of WebElement objects matching the locator -> Option A
  4. Quick Check:

    find_elements returns list [OK]
Hint: Remember: plural 'elements' means a list, not one item [OK]
Common Mistakes:
  • Confusing find_element (single) with find_elements (multiple)
  • Expecting a single WebElement instead of a list
  • Thinking it returns a count or boolean
2. Which of the following is the correct syntax to find all buttons on a page using Selenium Python?
easy
A. driver.find_elements(By.TAG_NAME, 'button')
B. driver.find_element(By.TAG_NAME, 'button')
C. driver.find_elements('button')
D. driver.find_element('button')

Solution

  1. Step 1: Use the correct method for multiple elements

    To find all buttons, use find_elements, not find_element.
  2. Step 2: Use the correct locator syntax

    The method requires two arguments: locator strategy and locator value, e.g., By.TAG_NAME and 'button'.
  3. Final Answer:

    driver.find_elements(By.TAG_NAME, 'button') -> Option A
  4. Quick Check:

    Correct method and locator = B [OK]
Hint: Use find_elements with By strategy and locator tuple [OK]
Common Mistakes:
  • Using find_element instead of find_elements
  • Passing only one argument instead of two
  • Using string locator without By class
3. What will be the output of this code snippet if the page has exactly 3 <li> elements?
items = driver.find_elements(By.TAG_NAME, 'li')
print(len(items))
medium
A. Error
B. 1
C. 0
D. 3

Solution

  1. Step 1: Understand what find_elements returns

    It returns a list of all matching elements. Here, it finds all <li> tags.
  2. Step 2: Use len() to count elements

    Since there are 3 <li> elements, len(items) returns 3.
  3. Final Answer:

    3 -> Option D
  4. Quick Check:

    Count of found elements = 3 [OK]
Hint: len() on find_elements list gives number found [OK]
Common Mistakes:
  • Expecting find_elements to return a single element
  • Confusing find_element with find_elements
  • Assuming print outputs elements instead of count
4. Identify the error in this code snippet:
elements = driver.find_elements(By.CLASS_NAME)
for el in elements:
print(el.text)
medium
A. Incorrect loop syntax
B. Using find_elements instead of find_element
C. Missing locator value argument in find_elements
D. Cannot print text of elements

Solution

  1. Step 1: Check find_elements method arguments

    find_elements requires two arguments: locator strategy and locator value. Here only one is given.
  2. Step 2: Understand the error cause

    Missing the second argument (the class name string) causes a TypeError.
  3. Final Answer:

    Missing locator value argument in find_elements -> Option C
  4. Quick Check:

    Two arguments needed for find_elements [OK]
Hint: Always provide locator type and value in find_elements [OK]
Common Mistakes:
  • Passing only locator type without value
  • Confusing find_element and find_elements usage
  • Assuming loop syntax is wrong
5. You want to click all links inside a <div> with id 'menu'. Which code correctly finds and clicks all these links?
hard
A. links = driver.find_element(By.CSS_SELECTOR, '#menu a') for link in links: link.click()
B. links = driver.find_elements(By.CSS_SELECTOR, '#menu a') for link in links: link.click()
C. links = driver.find_elements(By.ID, 'menu a') for link in links: link.click()
D. links = driver.find_elements(By.CLASS_NAME, 'menu a') for link in links: link.click()

Solution

  1. Step 1: Use correct locator for links inside #menu

    The CSS selector '#menu a' selects all <a> tags inside the element with id 'menu'.
  2. Step 2: Use find_elements to get all matching links

    find_elements returns a list of all matching elements, allowing iteration.
  3. Step 3: Loop through each link and click

    Iterate over the list and call click() on each WebElement.
  4. Final Answer:

    links = driver.find_elements(By.CSS_SELECTOR, '#menu a') for link in links: link.click() -> Option B
  5. Quick Check:

    Correct locator and method = A [OK]
Hint: Use CSS selector '#menu a' with find_elements to get all links [OK]
Common Mistakes:
  • Using find_element instead of find_elements
  • Wrong locator syntax for nested elements
  • Using By.ID with compound selector string
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard