karatelabs/karate · error · DriverException

inputFile failed: | locator: | files

Error message

inputFile failed: {errorMessage} | locator: {locator} | files: {files}

What it means

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.

Solutions

  1. Read the CDP errorMessage in the message; it usually names the invalid parameter (files vs objectId).
  2. Confirm the locator targets a real <input type=file>.
  3. Use absolute paths or verify the resolved path exists and is readable by the browser process.
  4. 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.

Example fix

// before
driver.inputFile('.dropzone', 'report.pdf'); // not a file input
// after
driver.inputFile('input[type=file]', '/abs/path/report.pdf');
Defensive patterns

Strategy: try-catch

Validate before calling

// validate inputs before the CDP call
java.io.File f = new java.io.File(path);
if (!f.isFile() || !f.canRead()) throw new IllegalStateException("unreadable file: " + path);

Try / catch

try {
    driver.inputFile(locator, files);
} catch (Exception e) {
    if (e.getMessage().startsWith("inputFile failed:")) {
        // message carries CDP errorMessage, locator and files for triage
        logger.warn("CDP rejected setFileInputFiles: {}", e.getMessage());
        throw e;
    } else throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12). Data as JSON: /api/errors/ff3cfe1208144c93. Report an issue: GitHub.

Appendix: source

Thrown at karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java:2961

     * CDP method that addresses the node by reference, which is what {@link #objectId(String)}
     * exists for. Existence-wait only: a file input is routinely {@code display:none} behind a
     * styled button, so the click/input visibility rules don't apply.
     */
    @Override
    public Element inputFile(String locator, String... files) {
        List<String> resolved = DriverApi.resolveFilePaths(files);
        logger.debug("inputFile: {} <- {}", locator, resolved);
        retryIfNeeded(locator);
        String objectId = objectId(locator);
        if (objectId == null) {
            throw new DriverException("inputFile: element did not resolve to a DOM node: " + locator);
        }
        CdpResponse response = cdp.method("DOM.setFileInputFiles")
                .param("files", resolved)
                .param("objectId", objectId)
                .send();
        if (response != null && response.isError()) {
            throw new DriverException("inputFile failed: " + response.getErrorMessage()
                    + " | locator: " + locator + " | files: " + resolved);
        }
        return BaseElement.existing(this, locator);
    }

    /**
     * Set the value of an input element.
     */
    public Element value(String locator, String value) {
        logger.debug("value: {} <- {}", locator, value);
        elementAction(locator, Locators.inputJs(locator, value));
        return BaseElement.existing(this, locator);
    }

    /**
     * Select an option from a dropdown by text or value.
     */
    public Element select(String locator, String text) {

View on GitHub (pinned to a22eb90246)