0
0
Selenium Javatesting~20 mins

findElements for multiple matches in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of findElements
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the size of the list returned by findElements?
Consider the following Selenium Java code snippet. What will be the size of the list elements after execution?
Selenium Java
List<WebElement> elements = driver.findElements(By.className("btn"));
System.out.println(elements.size());
AThe number of elements with class 'btn' on the current page
B0
C1
DThrows NoSuchElementException
Attempts:
2 left
💡 Hint
Remember that findElements returns a list of all matching elements or an empty list if none found.
assertion
intermediate
2:00remaining
Which assertion correctly verifies multiple elements are found?
You want to assert that at least 3 elements with tag name 'input' are present on the page. Which assertion is correct?
Selenium Java
List<WebElement> inputs = driver.findElements(By.tagName("input"));
AassertNull(inputs);
BassertTrue(inputs.size() >= 3);
CassertFalse(inputs.isEmpty());
DassertEquals(inputs.size(), 3);
Attempts:
2 left
💡 Hint
You want to check if there are three or more elements, not exactly three.
🔧 Debug
advanced
2:00remaining
Why does findElements return an empty list instead of throwing an exception?
You wrote code using findElements but it returns an empty list when no elements match. Why does it not throw NoSuchElementException like findElement?
ABecause the locator syntax is incorrect and silently ignored
BBecause findElements always returns null when no matches
CBecause the driver is not initialized properly
DBecause findElements is designed to return zero or more elements safely without exceptions
Attempts:
2 left
💡 Hint
Think about the difference in behavior between findElement and findElements.
locator
advanced
2:00remaining
Which locator finds multiple elements with attribute data-test='value'?
You want to find all elements with attribute data-test equal to value. Which locator is correct?
ABy.name("data-test='value'")
BBy.id("data-test='value'")
CBy.cssSelector("[data-test='value']")
DBy.className("data-test='value'")
Attempts:
2 left
💡 Hint
Attribute selectors in CSS use square brackets.
framework
expert
3:00remaining
How to handle stale element references when using findElements?
You use findElements to get multiple elements, but sometimes get StaleElementReferenceException when interacting with them. What is the best approach to handle this?
ARefetch the elements using findElements again before interacting with them
BCatch the exception and ignore it without retrying
CStore the elements once and reuse them without refetching
DUse findElement instead of findElements to avoid stale references
Attempts:
2 left
💡 Hint
Think about how page updates affect element references.