{"record":{"id":"30526772ba62ad32","repo":"SeleniumHQ/selenium","slug":"wrong-number-of-arguments-args-size-for-2","errorCode":null,"errorMessage":"wrong number of arguments (#{args.size} for 2)","messagePattern":"wrong number of arguments \\(#(.+?) for 2\\)","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/common/search_context.rb","lineNumber":109,"sourceCode":"      def extract_args(args)\n        case args.size\n        when 2\n          args\n        when 1\n          arg = args.first\n\n          unless arg.respond_to?(:shift)\n            raise ArgumentError,\n                  \"expected #{arg.inspect}:#{arg.class} to respond to #shift\"\n          end\n\n          # this will be a single-entry hash, so use #shift over #first or #[]\n          arr = arg.dup.shift\n          raise ArgumentError, \"expected #{arr.inspect} to have 2 elements\" unless arr.size == 2\n\n          arr\n        else\n          raise ArgumentError, \"wrong number of arguments (#{args.size} for 2)\"\n        end\n      end\n    end # SearchContext\n  end # WebDriver\nend # Selenium\n","sourceCodeStart":91,"sourceCodeEnd":115,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/common/search_context.rb#L91-L115","documentation":"Raised by SearchContext#extract_args when find_element or find_elements is called with 0 arguments or 3+ arguments. The method's case statement handles exactly 1 argument (Hash/Array form) or 2 arguments (how, what form); any other count falls to the else branch.","triggerScenarios":"Calling find_element() with no arguments. Calling find_element(:css, '#id', 'extra') with a spurious third argument. Calling find_element(a, b, c, d) where multiple locators are accidentally splatted in.","commonSituations":"Dynamic argument construction via splat (*) that sometimes produces 0 or 3+ args. Refactoring that accidentally drops or duplicates arguments. Calling find_element on an array that gets splatted incorrectly.","solutions":["Pass exactly 1 Hash argument or exactly 2 positional arguments (how, what).","If building arguments dynamically, validate the count before calling find_element.","Use array splat carefully: ensure find_element(*args) produces exactly 1 or 2 elements."],"exampleFix":"// before\nelement = driver.find_element  # no arguments\nelement = driver.find_element(:css, '#id', :extra)  # 3 arguments\n\n// after\nelement = driver.find_element(:css, '#id')","handlingStrategy":"validation","validationCode":"def safe_find(driver, *args)\n  unless [1, 2].include?(args.size)\n    raise ArgumentError, \"find_element takes 1 Hash or 2 args (how, what), got #{args.size}\"\n  end\n  driver.find_element(*args)\nend","typeGuard":null,"tryCatchPattern":"begin\n  driver.find_element(*args)\nrescue ArgumentError => e\n  raise unless e.message.include?('wrong number of arguments')\n  raise ArgumentError, \"Invalid find_element call with #{args.size} args: #{args.inspect}\"\nend","preventionTips":["Normalize locator arguments to a canonical [how, what] pair before calling find_element.","If using splat (*args), validate args.size is 1 or 2 before the call.","Write a wrapper method in your page objects that enforces the argument contract."],"tags":["find-element","argument-error","ruby"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}