karatelabs/karate · error · DriverException

select failed, no option matching

Error message

select failed, no option matching: '{text}' for: {locator}

What it means

Thrown by Driver.select when a dropdown option matching the given text or value cannot be found. The library runs a JS option-selector script against the page; if it does not return true, the option does not exist (yet) in the select element, so selecting is impossible and a DriverException is raised.

Solutions

  1. Print or log the select's options (e.g. script to list option texts) and match the exact text/value
  2. Wait for the dropdown to be populated before selecting (waitFor + retry/retryUntil)
  3. Select by value attribute instead of visible text, or vice versa, whichever matches
  4. Normalize case/whitespace in the string you pass

Example fix

// before
driver.select("#country", "united states");
// after
driver.waitFor("#country option");
driver.select("#country", "United States");
Defensive patterns

Strategy: try-catch

Validate before calling

// JS via driver.script before selecting
Object ok = driver.script(Locators.optionSelector("#country", "United States"));
if (!Boolean.TRUE.equals(ok)) {
    Object opts = driver.script("Array.from(document.querySelectorAll('#country option')).map(o => o.textContent)");
    throw new RuntimeException("option missing; available: " + opts);
}

Try / catch

try {
    driver.select("#country", "United States");
} catch (DriverException e) {
    if (e.getMessage().contains("select failed")) {
        driver.waitFor("#country option");
        driver.select("#country", "United States");
    } else { throw e; }
}

Prevention

When it happens

Trigger: Calling driver.select(locator, text) (or Element.select) where the <option> text/value does not exactly match the passed string; the dropdown has not rendered its options yet; options are loaded asynchronously via AJAX; text differs in case or whitespace.

Common situations: Testing pages where dropdown options are populated after page load, using label text instead of the option's value attribute, typos or trailing whitespace in the option text, dynamic options that change per user/session.

Related errors


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

Appendix: source

Thrown at karate-core/src/main/java/io/karatelabs/driver/Driver.java:956

    default Element inputFile(String locator, String... files) {
        throw new DriverException("inputFile not supported by this driver");
    }

    /**
     * Set the value of an input element directly.
     */
    default Element value(String locator, String value) {
        script(Locators.inputJs(locator, value));
        return BaseElement.of(this, locator);
    }

    /**
     * Select an option from a dropdown by text or value.
     */
    default Element select(String locator, String text) {
        Object matched = script(Locators.optionSelector(locator, text));
        if (!Boolean.TRUE.equals(matched)) {
            throw new DriverException("select failed, no option matching: '" + text + "' for: " + locator);
        }
        return BaseElement.of(this, locator);
    }

    /**
     * Select an option from a dropdown by index.
     */
    default Element select(String locator, int index) {
        String js = Locators.wrapInFunctionInvoke(
                "var e = " + Locators.selector(locator) + ";" +
                        " e.options[" + index + "].selected = true;" +
                        " e.dispatchEvent(new Event('input', {bubbles: true}));" +
                        " e.dispatchEvent(new Event('change', {bubbles: true}))");
        script(js);
        return BaseElement.of(this, locator);
    }

    /**

View on GitHub (pinned to a22eb90246)