karatelabs/karate · error · DriverException
select failed, no option matching
Error message
select failed, no option matching: '{text}' for: {locator} What it means
Karate's select() locates an <option> inside a dropdown by matching the given text (or value) via Locators.optionSelector and executes the option-selection action. If the action does not report success, no option matching the requested text exists in the select element.
Solutions
- Dump the dropdown's options at runtime and select an exact existing text/value.
- Wait for the options to load before selecting (e.g. driver.waitFor(locator + ' option')).
- Normalize case/whitespace in the text argument, or match by value attribute instead of label.
- Confirm the locator is a native <select>; for custom dropdown components click the component and option elements instead.
Example fix
// before
driver.select('#country', ' USA '); // mismatched whitespace
// after
driver.waitFor('#country option');
driver.select('#country', 'USA'); Defensive patterns
Strategy: validation
Validate before calling
// check the option exists before selecting
String script = "return Array.from(document.querySelectorAll('" + selectLocator + " option')).some(o => o.text.trim() === '" + text + "')";
Boolean ok = driver.script(script, null, Boolean.class);
if (!Boolean.TRUE.equals(ok)) throw new IllegalStateException("option missing: " + text); Try / catch
try {
driver.select(locator, text);
} catch (Exception e) {
if (e.getMessage().contains("select failed, no option matching")) {
driver.waitFor(locator + " option"); // options loaded late
driver.select(locator, text.trim());
} else throw e;
} Prevention
- waitFor option elements before selecting.
- Trim/normalize text and match on value when labels vary.
- Confirm the target is a native <select>, not a JS widget.
- Keep expected option values in sync with app copy.
When it happens
Trigger: driver.select(locator, text) (or * select step) where the option text/value does not exist in the dropdown, the locator points to a non-<select> element, or option markup uses whitespace/case that prevents the exact match.
Common situations: Dropdown options are loaded asynchronously after page load and the select ran too early; test data expects an option the app no longer offers; matching on visible label but the option's text differs (extra whitespace, HTML entities); custom JS dropdowns that are not native <select> elements.
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
- element not found:
- KARATE_ELEMENT_NOT_FOUND
- inputFile: element did not resolve to a DOM node
- element not found after
- element vanished during action after
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/65f259a3aba664eb.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/driver/cdp/CdpDriver.java:2983
}
/**
* 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) {
logger.debug("select: {} <- {}", locator, text);
Object matched = elementAction(locator, Locators.optionSelector(locator, text));
if (!Boolean.TRUE.equals(matched)) {
throw new DriverException("select failed, no option matching: '" + text + "' for: " + locator);
}
return BaseElement.existing(this, locator);
}
/**
* Select an option from a dropdown by index.
*/
public Element select(String locator, int index) {
logger.debug("select: {} <- index {}", locator, index);
retryIfNeeded(locator);
String js = Locators.wrapInFunctionInvoke(
"var e = " + Locators.selector(locator) + ";" +
" e.options[" + index + "].selected = true;" +
" " + Locators.commitFieldEventsJs("e"));
script(js);
return BaseElement.existing(this, locator);
}
View on GitHub (pinned to a22eb90246)