{"record":{"id":"c30e9dd1529cd14f","repo":"teamcapybara/capybara","slug":"result-failure-message-c30e9d","errorCode":null,"errorMessage":"result.failure_message","messagePattern":"result\\.failure_message","errorType":"exception","errorClass":"Capybara::ExpectationNotMet","httpStatus":null,"severity":"error","filePath":"lib/capybara/node/matchers.rb","lineNumber":112,"sourceCode":"      #\n      # It also accepts all options that {Capybara::Node::Finders#all} accepts,\n      # such as `:text` and `:visible`.\n      #\n      #     page.assert_selector('li', text: 'Horse', visible: true)\n      #\n      # {#assert_selector} can also accept XPath expressions generated by the\n      # XPath gem:\n      #\n      #     page.assert_selector(:xpath, XPath.descendant(:p))\n      #\n      # @param (see Capybara::Node::Finders#all)\n      # @option options [Integer] :count (nil)    Number of times the expression should occur\n      # @raise [Capybara::ExpectationNotMet]      If the selector does not exist\n      #\n      def assert_selector(*args, &optional_filter_block)\n        _verify_selector_result(args, optional_filter_block) do |result, query|\n          unless result.matches_count? && (result.any? || query.expects_none?)\n            raise Capybara::ExpectationNotMet, result.failure_message\n          end\n        end\n      end\n\n      ##\n      #\n      # Asserts that an element has the specified CSS styles.\n      #\n      #     element.assert_matches_style( 'color' => 'rgb(0,0,255)', 'font-size' => /px/ )\n      #\n      # @param styles [Hash]\n      # @raise [Capybara::ExpectationNotMet]    If the element doesn't have the specified styles\n      #\n      def assert_matches_style(styles = nil, **options)\n        styles, options = options, {} if styles.nil?\n        query_args, query_opts = _set_query_session_options(styles, options)\n        query = Capybara::Queries::StyleQuery.new(*query_args, **query_opts)\n        synchronize(query.wait) do","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/teamcapybara/capybara/blob/15b5fdb76e972e9623d5af2123ed3755594f9732/lib/capybara/node/matchers.rb#L94-L130","documentation":"Node::Matchers#assert_selector raises ExpectationNotMet with Result#failure_message when, after waiting, the resolved element set neither matches the count options nor contains anything (unless the query expects zero). The message reads 'expected to find <description> <count expectation>' plus what was actually found and elements that matched the selector but failed filters ('Also found ... which matched the selector but not all filters').","triggerScenarios":"page.assert_selector('table tr', count: 3) with 4 rows; element.assert_selector('li', minimum: 2) on an empty list; assert_selector(:field, 'Email', disabled: true) when the field is enabled; assert_selector('a', text: 'Home', visible: true) when the link is display:none.","commonSituations":"Timing races on dynamic pages, wrong counts after pagination/filtering, filters that silently exclude the intended elements, porting RSpec matchers (have_selector) to bare assert_* calls in minitest and hitting the same count semantics.","solutions":["Read the failure message: 'found N matches' tells you the real count; adjust the count option or the selector","If 'Also found ... not all filters' appears, loosen the failing filter (:text/:visible/:exact)","Increase wait: assert_selector('tr', count: 3, wait: 5)","Prefer the predicate when you need a boolean: page.has_selector?('tr', count: 3)"],"exampleFix":"# before\npage.assert_selector('table tbody tr', count: 5)\n\n# after\npage.assert_selector('table tbody tr', minimum: 1, wait: 5)\nexpect(page.all('table tbody tr').size).to eq(5)","handlingStrategy":"retry","validationCode":"n = page.all('table tbody tr').size\npage.assert_selector('table tbody tr', count: n) if n.positive?","typeGuard":null,"tryCatchPattern":"begin\n  page.assert_selector('tr', minimum: 1, wait: 5)\nrescue Capybara::ExpectationNotMet => e\n  puts e.message # lists actual matches and filter-excluded elements\n  raise\nend","preventionTips":["Read the 'Also found ... not all filters' section before loosening selectors","Start with minimum: 1 and tighten to count: once the page is deterministic","Keep assert_selector wait: aligned with the slowest environment (CI)"],"tags":["capybara","assertion","expectation-not-met","selector","count"],"backgroundTag":"selector-assertion-failed","analyzedSha":"15b5fdb76e972e9623d5af2123ed3755594f9732","analyzedAt":"2026-08-21T16:53:45.588Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}