{"record":{"id":"43a816ece362b862","repo":"karatelabs/karate","slug":"waitforurl-timeout-expected-url-containing-expected","errorCode":null,"errorMessage":"waitForUrl timeout: expected URL containing: ${expected}","messagePattern":"waitForUrl timeout: expected URL containing: (.+?)","errorType":"exception","errorClass":"DriverException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/w3c/W3cDriver.java","lineNumber":614,"sourceCode":"        throw new DriverException(\"waitForEnabled timeout: \" + locator);\n    }\n\n    @Override\n    public String waitForUrl(String expected) {\n        return waitForUrl(expected, options.getTimeoutDuration());\n    }\n\n    @Override\n    public String waitForUrl(String expected, java.time.Duration timeout) {\n        long deadline = System.currentTimeMillis() + timeout.toMillis();\n        while (System.currentTimeMillis() < deadline) {\n            String url = getUrl();\n            if (url != null && url.contains(expected)) {\n                return url;\n            }\n            sleep(options.getRetryInterval());\n        }\n        throw new DriverException(\"waitForUrl timeout: expected URL containing: \" + expected);\n    }\n\n    @Override\n    public Element waitUntil(String locator, String expression) {\n        return waitUntil(locator, expression, options.getTimeoutDuration());\n    }\n\n    @Override\n    public Element waitUntil(String locator, String expression, java.time.Duration timeout) {\n        long deadline = System.currentTimeMillis() + timeout.toMillis();\n        String js = Locators.scriptSelector(locator, expression);\n        while (System.currentTimeMillis() < deadline) {\n            try {\n                Object result = eval(js);\n                if (isTruthy(result)) {\n                    return BaseElement.existing(this, locator);\n                }\n            } catch (Exception e) {","sourceCodeStart":596,"sourceCodeEnd":632,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/w3c/W3cDriver.java#L596-L632","documentation":"W3cDriver.waitForUrl polls getUrl() every retry interval and returns as soon as the current URL contains the expected substring; if the URL never contains it within the timeout, a DriverException with the expected substring is thrown.","triggerScenarios":"Calling driver.waitForUrl(expected) after navigation-triggering actions (login, redirect) when the browser URL never contains the expected substring within the timeout — e.g. navigation never happened, redirect failed, or expected substring is wrong (trailing slash, http vs https, query params).","commonSituations":"Login rejected so no redirect occurs; expected URL uses a different base path or environment hostname; SPA changes route via hash while code expects a path substring; slow SSO redirect exceeding the timeout.","solutions":["Log driver.getUrl() after the action and compare with the expected substring","Increase the timeout via waitForUrl(expected, timeout)","Fix the expected substring to match the real URL scheme/host/path exactly","Verify the triggering action succeeded (check for error UI) before waiting on the URL"],"exampleFix":"// before\ndriver.waitForUrl('/dashboard'); // app actually lands on '/home'\n// after\ndriver.waitForUrl('/home', 15000);","handlingStrategy":"try-catch","validationCode":"if (driver.getUrl().contains(expected)) { /* already navigated */ }","typeGuard":null,"tryCatchPattern":"try {\n    driver.waitForUrl(expected, timeout);\n} catch (DriverException e) {\n    // log driver.getUrl() and current page title to diagnose failed navigation\n}","preventionTips":["Copy expected URL substrings from a real browser session in the target environment","Account for scheme/host/port differences between environments","Verify the navigation-triggering action succeeded before waiting"],"tags":["webdriver","timeout","navigation","url"],"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"}