{"record":{"id":"fded7b45276d5388","repo":"karatelabs/karate","slug":"waitforany-timeout-locators","errorCode":null,"errorMessage":"waitForAny timeout: ${locators}","messagePattern":"waitForAny timeout: (.+?)","errorType":"exception","errorClass":"DriverException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/w3c/W3cDriver.java","lineNumber":553,"sourceCode":"    }\n\n    @Override\n    public Element waitForAny(String[] locators) {\n        return waitForAny(locators, options.getTimeoutDuration());\n    }\n\n    @Override\n    public Element waitForAny(String[] locators, java.time.Duration timeout) {\n        long deadline = System.currentTimeMillis() + timeout.toMillis();\n        while (System.currentTimeMillis() < deadline) {\n            for (String locator : locators) {\n                if (exists(locator)) {\n                    return BaseElement.existing(this, locator);\n                }\n            }\n            sleep(options.getRetryInterval());\n        }\n        throw new DriverException(\"waitForAny timeout: \" + String.join(\", \", locators));\n    }\n\n    @Override\n    public Element waitForText(String locator, String expected) {\n        return waitForText(locator, expected, options.getTimeoutDuration());\n    }\n\n    @Override\n    public Element waitForText(String locator, String expected, java.time.Duration timeout) {\n        long deadline = System.currentTimeMillis() + timeout.toMillis();\n        while (System.currentTimeMillis() < deadline) {\n            try {\n                String text = text(locator);\n                if (text != null && text.contains(expected)) {\n                    return BaseElement.existing(this, locator);\n                }\n            } catch (Exception e) {\n                // Element may not exist yet","sourceCodeStart":535,"sourceCodeEnd":571,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/w3c/W3cDriver.java#L535-L571","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ndriver.waitForAny('#save-ok', '#save-error'); // neither appears, action not triggered\n// after\ndriver.click('#save');\ndriver.waitForAny('#save-ok', '#save-error', 30000);","handlingStrategy":"try-catch","validationCode":"// pre-check candidates\nboolean any = driver.exists(loc1) || driver.exists(loc2);","typeGuard":null,"tryCatchPattern":"try {\n    Element el = driver.waitForAny(loc1, loc2, timeout);\n} catch (DriverException e) {\n    // neither variant appeared; log page source and branch on failure\n}","preventionTips":["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"],"tags":["webdriver","timeout","wait","dom"],"backgroundTag":"request-timeout","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}