{"record":{"id":"c9d1c19dcd8906f8","repo":"SeleniumHQ/selenium","slug":"cannot-locate-element-with-text-text-inspect","errorCode":null,"errorMessage":"cannot locate element with text: #{text.inspect}","messagePattern":"cannot locate element with text: #(.+?)","errorType":"exception","errorClass":"Error::NoSuchElementError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/support/select.rb","lineNumber":168,"sourceCode":"        # Deselect all selected options. Only valid if the element supports multiple selections.\n        #\n        # @raise [Error::UnsupportedOperationError] if the element does not support multiple selections.\n        #\n\n        def deselect_all\n          raise Error::UnsupportedOperationError, 'you may only deselect all options of a multi-select' unless multiple?\n\n          options.each { |e| deselect_option e }\n        end\n\n        private\n\n        def select_by_text(text)\n          opts = find_by_text text\n\n          return select_options(opts) unless opts.empty?\n\n          raise Error::NoSuchElementError, \"cannot locate element with text: #{text.inspect}\"\n        end\n\n        def select_by_index(index)\n          opts = find_by_index index\n\n          return select_option(opts.first) unless opts.empty?\n\n          raise Error::NoSuchElementError, \"cannot locate element with index: #{index.inspect}\"\n        end\n\n        def select_by_value(value)\n          opts = find_by_value value\n\n          return select_options(opts) unless opts.empty?\n\n          raise Error::NoSuchElementError, \"cannot locate option with value: #{value.inspect}\"\n        end\n","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/support/select.rb#L150-L186","documentation":"In the private select_by_text helper, if no <option> whose visible text equals the argument is found, the binding raises Error::NoSuchElementError. This surfaces a genuine page-state mismatch (the option text you asked for is not present) using WebDriver's standard not-found error type.","triggerScenarios":"Calling select.select_by(:text, 'Bar') where no <option> has visible text exactly equal to 'Bar'. Whitespace-only or partial matches via find_by_text's fallback may still fail if no candidate matches exactly.","commonSituations":"Typo in the option text; the option text changed in a newer build; text includes extra whitespace the test didn't account for; the select is still loading options (race condition).","solutions":["Inspect select.options.map(&:text) to confirm the exact visible text available.","Use select_by(:value, ...) matching the option's value attribute if the visible text is unstable.","Wait for the option to be present (explicit wait) before selecting, to avoid load races."],"exampleFix":"# before\nselect.select_by(:text, 'Bar')\n\n# after\n Selenium::WebDriver::Wait.new.until { select.options.any? { |o| o.text == 'Bar' } }\nselect.select_by(:text, 'Bar')","handlingStrategy":"validation","validationCode":"Selenium::WebDriver::Wait.new.until { select.options.any? { |o| o.text == text } }\nselect.select_by(:text, text)","typeGuard":"def option_with_text?(select, text)\n  select.options.any? { |o| o.text == text }\nend","tryCatchPattern":"begin\n  select.select_by(:text, text)\nrescue Selenium::WebDriver::Error::NoSuchElementError => e\n  raise unless e.message.include?('cannot locate element with text')\n  # text not present — wait/retry or fail the test with context\nend","preventionTips":["Inspect select.options.map(&:text) to confirm exact visible text.","Use an explicit wait for the option before selecting.","Prefer select_by(:value) when visible text is volatile."],"tags":["select","no-such-element","ruby"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}