karatelabs/karate · error · DriverException
waitForAny timeout
Error message
waitForAny timeout: ${locators} What it means
W3cDriver.waitForAny polls each locator in the array every retry interval until the timeout elapses; if none of the locators ever exists, it throws a DriverException listing all locators joined by comma. It is the any-of variant of waitFor used when one of several possible elements is expected.
Solutions
- Test each locator individually in the browser to find the stale/incorrect one
- Increase the timeout via the waitForAny overload or driver options
- Confirm the triggering action (click/submit) actually happened before waiting
- If neither branch should occur, add logging of page content (driver.html('body')) to diagnose
Example fix
// before
driver.waitForAny('#save-ok', '#save-error'); // neither appears, action not triggered
// after
driver.click('#save');
driver.waitForAny('#save-ok', '#save-error', 30000); Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check candidates boolean any = driver.exists(loc1) || driver.exists(loc2);
Try / catch
try {
Element el = driver.waitForAny(loc1, loc2, timeout);
} catch (DriverException e) {
// neither variant appeared; log page source and branch on failure
} Prevention
- Keep candidate locator lists minimal and devtools-verified
- Confirm the triggering action completed before the wait
- Set generous timeouts when waiting on UI outcomes of network calls
When it happens
Trigger: Calling driver.waitForAny(locator1, locator2, ...) or waitForAny(String[]) where none of the supplied locators exists at any poll within the timeout; also raised when all candidate selectors are wrong or the page state never reaches any of the expected variants.
Common situations: Awaiting one of two dialog variants (success/error) that never appears because the action silently failed; copy-pasted locators that no longer match after a UI redesign; timeout too short for slow envs.
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
- waitFor timeout
- waitForText timeout: expected
- waitForEnabled timeout
- waitUntil timeout: expression
- waitUntil timeout
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/fded7b45276d5388.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/driver/w3c/W3cDriver.java:553
}
@Override
public Element waitForAny(String[] locators) {
return waitForAny(locators, options.getTimeoutDuration());
}
@Override
public Element waitForAny(String[] locators, java.time.Duration timeout) {
long deadline = System.currentTimeMillis() + timeout.toMillis();
while (System.currentTimeMillis() < deadline) {
for (String locator : locators) {
if (exists(locator)) {
return BaseElement.existing(this, locator);
}
}
sleep(options.getRetryInterval());
}
throw new DriverException("waitForAny timeout: " + String.join(", ", locators));
}
@Override
public Element waitForText(String locator, String expected) {
return waitForText(locator, expected, options.getTimeoutDuration());
}
@Override
public Element waitForText(String locator, String expected, java.time.Duration timeout) {
long deadline = System.currentTimeMillis() + timeout.toMillis();
while (System.currentTimeMillis() < deadline) {
try {
String text = text(locator);
if (text != null && text.contains(expected)) {
return BaseElement.existing(this, locator);
}
} catch (Exception e) {
// Element may not exist yetView on GitHub (pinned to a22eb90246)