{"record":{"id":"7b075cd7fdcbbfba","repo":"SeleniumHQ/selenium","slug":"expected-arg-inspect-arg-class-to-respond-to","errorCode":null,"errorMessage":"expected #{arg.inspect}:#{arg.class} to respond to #shift","messagePattern":"expected #(.+?):#(.+?) to respond to #shift","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/common/search_context.rb","lineNumber":99,"sourceCode":"        how, what = extract_args(args)\n\n        by = SearchContext.finders[how.to_sym]\n        raise ArgumentError, \"cannot find elements by #{how.inspect}\" unless by\n\n        bridge.find_elements_by by, what, ref\n      end\n\n      private\n\n      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":81,"sourceCodeEnd":115,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/common/search_context.rb#L81-L115","documentation":"Raised by SearchContext#extract_args (private) when find_element or find_elements is called with exactly one argument that does not respond to the :shift method (i.e., not a Hash or Array-like object). The method expects either two positional args (how, what) or a single Hash/Array that can be shifted into a key-value or [key, value] pair.","triggerScenarios":"Calling find_element('css') with only a strategy and no locator value. Calling find_element(42) or find_element(nil) with a non-Hash, non-Array argument. Calling find_element(SomeObject.new) with an arbitrary object.","commonSituations":"Forgot the second argument (the locator value). Passing a driver or element object as the sole argument by mistake. Variable interpolation producing nil where a Hash was expected.","solutions":["Pass two arguments: find_element(:css, '#my-id').","Or pass a single Hash: find_element(css: '#my-id').","Check that the variable holding your locator options is not nil before calling find_element."],"exampleFix":"// before\nelement = driver.find_element(:css)  # missing the locator value\n\n// after\nelement = driver.find_element(:css, '#submit')","handlingStrategy":"type-guard","validationCode":"def safe_find(driver, *args)\n  if args.size == 1 && !args.first.respond_to?(:shift)\n    raise ArgumentError, \"Single argument must be a Hash or Array, got #{args.first.class}\"\n  end\n  driver.find_element(*args)\nend","typeGuard":"def valid_find_arg?(arg)\n  arg.respond_to?(:shift)\nend","tryCatchPattern":"begin\n  driver.find_element(locator)\nrescue ArgumentError => e\n  raise unless e.message.include?('to respond to #shift')\n  # locator is not a Hash; wrap it\n  driver.find_element(*Array(locator))\nend","preventionTips":["Standardize on the two-argument form find_element(how, what) to avoid Hash/Array ambiguity.","If building locators dynamically, type-check before calling find_element.","Add RuboCop or custom linters to catch bare single-argument find_element calls."],"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"}