karatelabs/karate · error · DriverException
timeout waiting for any element
Error message
timeout waiting for any element: ${locators} What it means
driver.waitForAny(locators) polls until at least one of the supplied locators exists, then returns an Element for the first match. If none of the locators match within the timeout, it throws with the comma-joined locator list.
Solutions
- Check the page state after the triggering action; add asserts/logs to confirm it succeeded before waiting for outcomes.
- Update the locator list to cover the actual possible outcomes (inspect the DOM in both branches).
- Increase the timeout to accommodate the slowest realistic outcome.
- Catch DriverException and capture the page source/driver state to diagnose which branch never rendered.
Example fix
// before
Element e = driver.waitForAny('.toast-success', '.toast-error'); // neither appears
// after
driver.click('#save');
Element e = driver.waitForAny('.toast-success', '.toast-error', '.form-error-inline', Duration.ofSeconds(15)); Defensive patterns
Strategy: try-catch
Validate before calling
// assert the triggering action produced some visible outcome first
if (driver.exists(".app-crash-screen")) throw new AssertionError("app crashed before waitAny"); Try / catch
try {
Element e = driver.waitForAny(".toast-success", ".toast-error");
} catch (Exception e) {
if (e.getMessage().startsWith("timeout waiting for any element")) {
throw new AssertionError("none of the outcomes appeared: " + e.getMessage(), e);
} else throw e;
} Prevention
- Enumerate all possible UI outcomes in the locator list.
- Verify the preceding action succeeded before waiting for its results.
- Include a neutral fallback locator (e.g. unchanged-state marker).
- Size the timeout for the slowest branch.
When it happens
Trigger: driver.waitForAny(String... locators) where every provided selector fails to match during the poll window — e.g. waiting for either a success or error banner but neither rendered because the triggering action failed.
Common situations: Race where the preceding action silently failed so neither expected outcome appeared; all candidate selectors stale after a UI redesign; page navigated away so none of the candidates exist; timeout shorter than the app's response time.
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 element
- timeout waiting for text
- timeout waiting for element to be enabled
- timeout waiting for elements
- element not found after
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/bc4b3df6a8c1348b.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java:3324
*/
public Element waitForAny(String[] locators) {
return waitForAny(locators, options.getTimeoutDuration());
}
/**
* Wait for any of the locators to match with custom timeout.
*/
public Element waitForAny(String[] locators, Duration timeout) {
Element found = pollFor(timeout.toMillis(), options.getRetryInterval(), () -> {
for (String locator : locators) {
if (exists(locator)) {
return BaseElement.existing(this, locator);
}
}
return null;
});
if (found == null) {
throw new DriverException("timeout waiting for any element: " + String.join(", ", locators));
}
return found;
}
/**
* Wait for an element to contain specific text.
*/
public Element waitForText(String locator, String expected) {
return waitForText(locator, expected, options.getTimeoutDuration());
}
/**
* Wait for an element to contain specific text with custom timeout.
*/
public Element waitForText(String locator, String expected, Duration timeout) {
Element found = pollFor(timeout.toMillis(), options.getRetryInterval(), () -> {
if (exists(locator)) {
String text = text(locator);View on GitHub (pinned to a22eb90246)