{"record":{"id":"ff3cfe1208144c93","repo":"karatelabs/karate","slug":"inputfile-failed-errormessage-locator-locator-files-files","errorCode":null,"errorMessage":"inputFile failed: {errorMessage} | locator: {locator} | files: {files}","messagePattern":"inputFile failed: (.+?) \\| locator: (.+?) \\| files: (.+?)","errorType":"exception","errorClass":"DriverException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java","lineNumber":2961,"sourceCode":"     * 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));\n        return BaseElement.existing(this, locator);\n    }\n\n    /**\n     * Select an option from a dropdown by text or value.\n     */\n    public Element select(String locator, String text) {","sourceCodeStart":2943,"sourceCodeEnd":2979,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java#L2943-L2979","documentation":"Karate sent the DOM.setFileInputFiles CDP command to attach files to an <input type=file>, but the browser returned an error response. The exception embeds the CDP error message, the locator, and the resolved file paths.","triggerScenarios":"driver.inputFile(locator, files...) where the CDP call fails: the objectId refers to a node that is not a file input, a resolved file path is invalid/inaccessible to the browser, or the node was destroyed between resolution and the call.","commonSituations":"Targeting a non-file input (e.g. a text input or a styled div pretending to be an upload button); relative path resolved against the wrong working directory; file deleted after path resolution; browser sandbox lacks permission to read the file; multiple files passed to a non-multiple input.","solutions":["Read the CDP errorMessage in the message; it usually names the invalid parameter (files vs objectId).","Confirm the locator targets a real <input type=file>.","Use absolute paths or verify the resolved path exists and is readable by the browser process.","Retry after re-waiting for the element if it was re-rendered between resolution and the call; for single-file inputs pass exactly one file."],"exampleFix":"// before\ndriver.inputFile('.dropzone', 'report.pdf'); // not a file input\n// after\ndriver.inputFile('input[type=file]', '/abs/path/report.pdf');","handlingStrategy":"try-catch","validationCode":"// validate inputs before the CDP call\njava.io.File f = new java.io.File(path);\nif (!f.isFile() || !f.canRead()) throw new IllegalStateException(\"unreadable file: \" + path);","typeGuard":null,"tryCatchPattern":"try {\n    driver.inputFile(locator, files);\n} catch (Exception e) {\n    if (e.getMessage().startsWith(\"inputFile failed:\")) {\n        // message carries CDP errorMessage, locator and files for triage\n        logger.warn(\"CDP rejected setFileInputFiles: {}\", e.getMessage());\n        throw e;\n    } else throw e;\n}","preventionTips":["Only target native <input type=file> elements.","Resolve to absolute readable paths before upload.","Pass one file unless the input has the multiple attribute.","Re-resolve the element right before upload to avoid stale objectIds."],"tags":["driver","file-upload","cdp","dom"],"backgroundTag":"api-error-response","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"}