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
- Print or log the select's options (e.g. script to list option texts) and match the exact text/value
- Wait for the dropdown to be populated before selecting (waitFor + retry/retryUntil)
- Select by value attribute instead of visible text, or vice versa, whichever matches
- 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
- Wait for options to render before selecting
- Match option value vs visible text deliberately
- Trim/case-normalize the option string
- Log available options on failure for diagnosis
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
- no element found matching
- driver keyword requires a URL argument
- driver URL evaluated to null:
- element not found:
- missing array argument 'patterns':
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)