{"record":{"id":"bcf56e4f67bed5ef","repo":"karatelabs/karate","slug":"inputfile-element-did-not-resolve-to-a-dom-node-locator","errorCode":null,"errorMessage":"inputFile: element did not resolve to a DOM node: {locator}","messagePattern":"inputFile: element did not resolve to a DOM node: (.+?)","errorType":"exception","errorClass":"DriverException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java","lineNumber":2954,"sourceCode":"            keys().type(value);\n        }\n        return BaseElement.existing(this, locator);\n    }\n\n    /**\n     * Set the files of a file {@code <input>} element via {@code DOM.setFileInputFiles} — the\n     * CDP method that addresses the node by reference, which is what {@link #objectId(String)}\n     * exists for. Existence-wait only: a file input is routinely {@code display:none} behind a\n     * styled button, so the click/input visibility rules don't apply.\n     */\n    @Override\n    public Element inputFile(String locator, String... files) {\n        List<String> resolved = DriverApi.resolveFilePaths(files);\n        logger.debug(\"inputFile: {} <- {}\", locator, resolved);\n        retryIfNeeded(locator);\n        String objectId = objectId(locator);\n        if (objectId == null) {\n            throw new DriverException(\"inputFile: element did not resolve to a DOM node: \" + locator);\n        }\n        CdpResponse response = cdp.method(\"DOM.setFileInputFiles\")\n                .param(\"files\", resolved)\n                .param(\"objectId\", objectId)\n                .send();\n        if (response != null && response.isError()) {\n            throw new DriverException(\"inputFile failed: \" + response.getErrorMessage()\n                    + \" | locator: \" + locator + \" | files: \" + resolved);\n        }\n        return BaseElement.existing(this, locator);\n    }\n\n    /**\n     * Set the value of an input element.\n     */\n    public Element value(String locator, String value) {\n        logger.debug(\"value: {} <- {}\", locator, value);\n        elementAction(locator, Locators.inputJs(locator, value));","sourceCodeStart":2936,"sourceCodeEnd":2972,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java#L2936-L2972","documentation":"Karate's inputFile() resolves the locator to a DOM node and obtains its CDP remote objectId to attach files. If objectId(locator) returns null, the element did not resolve to a live DOM node, so the file cannot be set on the input.","triggerScenarios":"Calling driver.inputFile(locator, files...) (or * inputFile step) when the element does not exist in the current frame/document, is in a different frame, or the node reference could not be obtained after retryIfNeeded(locator).","commonSituations":"Typo in input locator; element inside an iframe that was not switched to; page reloaded between locating and file upload; element rendered only after user interaction that the test skipped; hidden/virtual inputs not present in the DOM.","solutions":["Verify the locator matches an <input type=file> element present in the DOM (check in DevTools).","Switch to the correct frame first if the input lives inside an iframe.","Wait for the element before uploading: driver.waitFor(locator) then driver.inputFile(locator, file).","Use an absolute or correctly-relative file path (DriverApi.resolveFilePaths) and confirm the element is rendered after prior steps complete."],"exampleFix":"// before\ndriver.inputFile('#upload', 'data/file.pdf'); // element not rendered yet\n// after\ndriver.waitFor('#upload');\ndriver.inputFile('#upload', 'data/file.pdf');","handlingStrategy":"validation","validationCode":"// confirm the file input exists before uploading\nif (!driver.exists(\"input[type=file]#upload\")) {\n    throw new IllegalStateException(\"file input not present: #upload\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    driver.inputFile(locator, files);\n} catch (Exception e) {\n    if (e.getMessage().contains(\"did not resolve to a DOM node\")) {\n        driver.waitFor(locator, Duration.ofSeconds(10));\n        driver.inputFile(locator, files);\n    } else throw e;\n}","preventionTips":["waitFor the input before calling inputFile.","Switch to the containing iframe first.","Use absolute file paths verified with Files.exists().","Re-locate the element after any navigation or modal open."],"tags":["driver","file-upload","element-not-found","cdp"],"backgroundTag":"entity-not-found","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"}