{"record":{"id":"6fa6cac53420899a","repo":"teamcapybara/capybara","slug":"value-cannot-be-an-array-when-multiple-attribute","errorCode":null,"errorMessage":"Value cannot be an Array when 'multiple' attribute is not present. Not a #{value.class}","messagePattern":"Value cannot be an Array when 'multiple' attribute is not present\\. Not a #(.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/capybara/rack_test/node.rb","lineNumber":37,"sourceCode":"  def [](name)\n    string_node[name]\n  end\n\n  def style(_styles)\n    raise NotImplementedError, 'The rack_test driver does not process CSS'\n  end\n\n  def value\n    string_node.value\n  end\n\n  def set(value, **options)\n    return if disabled? || readonly?\n\n    warn \"Options passed to Node#set but the RackTest driver doesn't support any - ignoring\" unless options.empty?\n\n    if value.is_a?(Array) && !multiple?\n      raise TypeError, \"Value cannot be an Array when 'multiple' attribute is not present. Not a #{value.class}\"\n    end\n\n    if radio? then set_radio(value)\n    elsif checkbox? then set_checkbox(value)\n    elsif range? then set_range(value)\n    elsif input_field? then set_input(value)\n    elsif textarea? then native['_capybara_raw_value'] = value.to_s\n    end\n  end\n\n  def select_option\n    return if disabled?\n\n    deselect_options unless select_node.multiple?\n    native['selected'] = 'selected'\n  end\n\n  def unselect_option","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/teamcapybara/capybara/blob/15b5fdb76e972e9623d5af2123ed3755594f9732/lib/capybara/rack_test/node.rb#L19-L55","documentation":"Under rack_test, Node#set accepts an Array only for elements that can hold multiple values (i.e. a <select multiple>). If the value is an Array but the element lacks the 'multiple' attribute, it raises TypeError naming the rejected class. This is a fail-fast shape check before any mutation of the DOM.","triggerScenarios":"find('#topics').set(['ruby', 'go']) where #topics is a <select> without multiple or a text input; a shared fill helper doing fill_in(field, with: params[:tags]) where params[:tags] arrives as an Array for a non-multiple field.","commonSituations":"A helper written for multi-selects reused on single-selects; the frontend markup changed and lost the multiple attribute; Rails form params (arrays for check-box collections) passed straight into set; data-driven steps where the fixture sometimes yields arrays.","solutions":["Pass a scalar for single-valued fields: find('#topics').set('ruby') or use the select API: page.select('Ruby', from: 'Topics').","Add the multiple attribute to the <select> element if multi-selection is the intended behavior.","Normalize inputs in the helper: collapse arrays to their first element for non-multiple fields (or reject them) before calling set.","Branch on the element: use set(array) only when find_field('X').multiple? is true."],"exampleFix":"# before\nfind('#topics').set(['ruby', 'go']) # <select> without multiple\n\n# after\nselect_el = find('#topics')\nselect_el.multiple? ? select_el.set(['ruby', 'go']) : select_el.set('ruby')","handlingStrategy":"type-guard","validationCode":"value = ['ruby', 'go']\nnode = find('#topics')\nraise TypeError, 'Array value needs multiple=true' if value.is_a?(Array) && !node.multiple?\nnode.set(value)","typeGuard":"def settable?(node, value)\n  !value.is_a?(Array) || node.multiple?\nend","tryCatchPattern":null,"preventionTips":["Normalize incoming params in fill helpers: collapse single-element arrays for non-multiple fields before calling set.","Prefer select/select_option APIs over set for <select> elements so semantics are enforced by intent."],"tags":["ruby","capybara","rack-test","forms","type-error"],"backgroundTag":"invalid-argument-type","analyzedSha":"15b5fdb76e972e9623d5af2123ed3755594f9732","analyzedAt":"2026-08-21T16:53:45.588Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}