{"record":{"id":"56a3f95e3c2fcc4e","repo":"karatelabs/karate","slug":"select-failed-no-option-matching-text-for-locator","errorCode":null,"errorMessage":"select failed, no option matching: '{text}' for: {locator}","messagePattern":"select failed, no option matching: '(.+?)' for: (.+?)","errorType":"exception","errorClass":"DriverException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/Driver.java","lineNumber":956,"sourceCode":"    default Element inputFile(String locator, String... files) {\n        throw new DriverException(\"inputFile not supported by this driver\");\n    }\n\n    /**\n     * Set the value of an input element directly.\n     */\n    default Element value(String locator, String value) {\n        script(Locators.inputJs(locator, value));\n        return BaseElement.of(this, locator);\n    }\n\n    /**\n     * Select an option from a dropdown by text or value.\n     */\n    default Element select(String locator, String text) {\n        Object matched = script(Locators.optionSelector(locator, text));\n        if (!Boolean.TRUE.equals(matched)) {\n            throw new DriverException(\"select failed, no option matching: '\" + text + \"' for: \" + locator);\n        }\n        return BaseElement.of(this, locator);\n    }\n\n    /**\n     * Select an option from a dropdown by index.\n     */\n    default Element select(String locator, int index) {\n        String js = Locators.wrapInFunctionInvoke(\n                \"var e = \" + Locators.selector(locator) + \";\" +\n                        \" e.options[\" + index + \"].selected = true;\" +\n                        \" e.dispatchEvent(new Event('input', {bubbles: true}));\" +\n                        \" e.dispatchEvent(new Event('change', {bubbles: true}))\");\n        script(js);\n        return BaseElement.of(this, locator);\n    }\n\n    /**","sourceCodeStart":938,"sourceCodeEnd":974,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/Driver.java#L938-L974","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ndriver.select(\"#country\", \"united states\");\n// after\ndriver.waitFor(\"#country option\");\ndriver.select(\"#country\", \"United States\");","handlingStrategy":"try-catch","validationCode":"// JS via driver.script before selecting\nObject ok = driver.script(Locators.optionSelector(\"#country\", \"United States\"));\nif (!Boolean.TRUE.equals(ok)) {\n    Object opts = driver.script(\"Array.from(document.querySelectorAll('#country option')).map(o => o.textContent)\");\n    throw new RuntimeException(\"option missing; available: \" + opts);\n}","typeGuard":null,"tryCatchPattern":"try {\n    driver.select(\"#country\", \"United States\");\n} catch (DriverException e) {\n    if (e.getMessage().contains(\"select failed\")) {\n        driver.waitFor(\"#country option\");\n        driver.select(\"#country\", \"United States\");\n    } else { throw e; }\n}","preventionTips":["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"],"tags":["driver","ui","selector"],"backgroundTag":"element-not-found","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}