{"record":{"id":"85afcd6d70a093e7","repo":"karatelabs/karate","slug":"timeout-waiting-for-element-to-be-enabled-locator","errorCode":null,"errorMessage":"timeout waiting for element to be enabled: ${locator}","messagePattern":"timeout waiting for element to be enabled: (.+?)","errorType":"exception","errorClass":"DriverException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java","lineNumber":3369,"sourceCode":"        }\n        return found;\n    }\n\n    /**\n     * Wait for an element to be enabled.\n     */\n    public Element waitForEnabled(String locator) {\n        return waitForEnabled(locator, options.getTimeoutDuration());\n    }\n\n    /**\n     * Wait for an element to be enabled with custom timeout.\n     */\n    public Element waitForEnabled(String locator, Duration timeout) {\n        Element found = pollFor(timeout.toMillis(), options.getRetryInterval(),\n                () -> exists(locator) && enabled(locator) ? BaseElement.existing(this, locator) : null);\n        if (found == null) {\n            throw new DriverException(\"timeout waiting for element to be enabled: \" + locator);\n        }\n        return found;\n    }\n\n    /**\n     * Wait for URL to contain expected string.\n     */\n    public String waitForUrl(String expected) {\n        return waitForUrl(expected, options.getTimeoutDuration());\n    }\n\n    /**\n     * Wait for URL to contain expected string with custom timeout.\n     */\n    public String waitForUrl(String expected, Duration timeout) {\n        String found = pollFor(timeout.toMillis(), options.getRetryInterval(), () -> {\n            String url = getUrl();\n            return url != null && url.contains(expected) ? url : null;","sourceCodeStart":3351,"sourceCodeEnd":3387,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java#L3351-L3387","documentation":"CdpDriver.waitForEnabled(locator, timeout) polls until the element both exists and is enabled (per the browser's DOM disabled state). If the poll budget elapses without such an element, a DriverException is thrown with the locator embedded in the message. It is Karate's explicit signal that an element never became interactive within the allotted wait.","triggerScenarios":"Calling driver.waitForEnabled(locator, duration) (or the driver.waitForEnabled(locator) keyword with default timeout) when the element is absent, is disabled via the HTML 'disabled' attribute/property, or is inside a container Karate cannot reach before the timeout expires.","commonSituations":"Element is permanently disabled until a form is valid; element only appears after a slow AJAX call that exceeds the configured retry/timeout budget; wrong selector matches nothing; app rendered a disabled button due to a validation error the test did not anticipate; timeout too short on slow CI machines.","solutions":["Increase the timeout argument or the driver retry/timeout configuration so slow renders are covered","Verify the locator actually resolves (use exists(locator) or locateAll) before blaming enabled state","If the element must be enabled programmatically, remove the disabled attribute via driver.script before waiting","Click/wait on the element that enables it first (e.g. fill required fields) instead of waiting on a permanently disabled control"],"exampleFix":"// before\nElement el = driver.waitForEnabled(\"#submit\", Duration.ofSeconds(2));\n// after\nElement el = driver.waitForEnabled(\"#submit\", Duration.ofSeconds(15));","handlingStrategy":"try-catch","validationCode":"// before waiting, confirm the element exists\nif (!driver.exists(\"#submit\")) { throw new IllegalStateException(\"#submit not in DOM\"); }\nString disabled = (String) driver.script(\"#submit\", \"_.disabled\");\nif (Boolean.parseBoolean(String.valueOf(disabled))) { logger.warn(\"#submit currently disabled\"); }","typeGuard":null,"tryCatchPattern":"try {\n    Element el = driver.waitForEnabled(\"#submit\", Duration.ofSeconds(15));\n} catch (DriverException e) {\n    logger.error(\"element never enabled: {} | url={}\", e.getMessage(), driver.getUrl());\n    throw e;\n}","preventionTips":["Always pass an explicit generous timeout instead of relying on the default","Check exists() before waiting on enabled state to separate 'not found' from 'disabled'","After a failure, dump the element's disabled attribute and page URL for diagnosis"],"tags":["driver","timeout","element-enabled","wait"],"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"}