karatelabs/karate · error · DriverException

inputFile: element did not resolve to a DOM node

Error message

inputFile: element did not resolve to a DOM node: {locator}

What it means

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.

Solutions

  1. Verify the locator matches an <input type=file> element present in the DOM (check in DevTools).
  2. Switch to the correct frame first if the input lives inside an iframe.
  3. Wait for the element before uploading: driver.waitFor(locator) then driver.inputFile(locator, file).
  4. Use an absolute or correctly-relative file path (DriverApi.resolveFilePaths) and confirm the element is rendered after prior steps complete.

Example fix

// before
driver.inputFile('#upload', 'data/file.pdf'); // element not rendered yet
// after
driver.waitFor('#upload');
driver.inputFile('#upload', 'data/file.pdf');
Defensive patterns

Strategy: validation

Validate before calling

// confirm the file input exists before uploading
if (!driver.exists("input[type=file]#upload")) {
    throw new IllegalStateException("file input not present: #upload");
}

Try / catch

try {
    driver.inputFile(locator, files);
} catch (Exception e) {
    if (e.getMessage().contains("did not resolve to a DOM node")) {
        driver.waitFor(locator, Duration.ofSeconds(10));
        driver.inputFile(locator, files);
    } else throw e;
}

Prevention

When it happens

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

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

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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

Appendix: source

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

            keys().type(value);
        }
        return BaseElement.existing(this, locator);
    }

    /**
     * Set the files of a file {@code <input>} element via {@code DOM.setFileInputFiles} — the
     * 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));

View on GitHub (pinned to a22eb90246)