karatelabs/karate · error · DriverException
waitForResultCount timeout
Error message
waitForResultCount timeout: ${locator} expected count: ${count} What it means
W3cDriver.waitForResultCount polls locateAll(locator) every retry interval and returns only when the matched element count exactly equals the expected count; otherwise, after the timeout, it throws a DriverException naming the locator and expected count.
Solutions
- Log locateAll(locator).size() to see the actual count and compare with expected
- Refine the selector (scope, :visible-style filters) so it matches exactly the intended nodes
- Increase the timeout via waitForResultCount(locator, count, timeout)
- If exact equality is too strict, poll and assert a >= or <= condition instead
Example fix
// before
driver.waitForResultCount('table tr', 5); // header row makes it 6
// after
driver.waitForResultCount('table tbody tr', 5); Defensive patterns
Strategy: validation
Validate before calling
int actual = driver.locateAll(locator).size();
if (actual != expected) { /* adjust selector or expected count */ } Try / catch
try {
List<Element> rows = driver.waitForResultCount(locator, count, timeout);
} catch (DriverException e) {
// log driver.locateAll(locator).size() to compare actual vs expected
} Prevention
- Scope selectors (tbody, container id) to avoid counting headers/templates
- Verify final rendered count in the browser before hardcoding it
- Prefer a range/predicate when exact equality is not the real requirement
When it happens
Trigger: Calling driver.waitForResultCount(locator, count) when the number of matched elements never equals count — too few (list still loading, filter not applied) or too many (duplicates, selector too broad) within the timeout.
Common situations: Waiting for a table to show exactly N rows but pagination/lazy-loading changes the count; selector matches hidden template nodes inflating the count; expected count off by one due to a header row; async data fetch slower than timeout.
Understand the failure class
Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- timeout waiting for elements
- waitFor timeout
- waitForAny timeout
- waitForText timeout: expected
- waitForEnabled timeout
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/6df13788bf3fda87.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/driver/w3c/W3cDriver.java:695
throw new DriverException("waitUntil (supplier) timeout");
}
@Override
public List<Element> waitForResultCount(String locator, int count) {
return waitForResultCount(locator, count, options.getTimeoutDuration());
}
@Override
public List<Element> waitForResultCount(String locator, int count, java.time.Duration timeout) {
long deadline = System.currentTimeMillis() + timeout.toMillis();
while (System.currentTimeMillis() < deadline) {
List<Element> results = locateAll(locator);
if (results.size() == count) {
return results;
}
sleep(options.getRetryInterval());
}
throw new DriverException("waitForResultCount timeout: " + locator + " expected count: " + count);
}
// ========== Navigation ==========
@Override
public String getUrl() {
return session.getUrl();
}
@Override
public String getTitle() {
return session.getTitle();
}
// ========== Cookies ==========
@Override
public void deleteCookie(String name) {View on GitHub (pinned to a22eb90246)