{"record":{"id":"9e6abc82d4bd1e9b","repo":"SeleniumHQ/selenium","slug":"button-is-not-a-valid-button","errorCode":null,"errorMessage":"#{button} is not a valid button!","messagePattern":"#(.+?) is not a valid button!","errorType":"exception","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/common/interactions/pointer_press.rb","lineNumber":65,"sourceCode":"          @button = assert_button(button)\n          @type = @direction\n          @opts = opts\n        end\n\n        def encode\n          process_opts.merge('type' => type.to_s, 'button' => @button)\n        end\n\n        private\n\n        def assert_source(source)\n          raise TypeError, \"#{source.type} is not a valid input type\" unless source.is_a? PointerInput\n        end\n\n        def assert_button(button)\n          case button\n          when Symbol\n            raise ArgumentError, \"#{button} is not a valid button!\" unless BUTTONS.key? button\n\n            BUTTONS[button]\n          when Integer\n            raise ArgumentError, 'Button number cannot be negative!' if button.negative?\n\n            button\n          else\n            raise TypeError, \"button must be a positive integer or one of #{BUTTONS.keys}, not #{button.class}\"\n          end\n        end\n\n        def assert_direction(direction)\n          raise ArgumentError, \"#{direction.inspect} is not a valid button direction\" unless DIRECTIONS.key? direction\n\n          DIRECTIONS[direction]\n        end\n      end # PointerPress\n    end # Interactions","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/common/interactions/pointer_press.rb#L47-L83","documentation":"Raised as ArgumentError by PointerPress#assert_button when button is a Symbol that is not a key in BUTTONS. Recognized Symbol buttons: :left, :touch, :pen_contact, :middle, :right, :pen_barrel, :x1, :back, :x2, :forward (mapped to integer codes 0–4).","triggerScenarios":"Calling pointer_down/pointer_up (or PointerPress.new) with a Symbol like :center, :wheel, :side, or a typo such as :lef. Also when reusing a Symbol constant from another library (e.g. Appium's :finger).","commonSituations":"Guessing button names; copy-pasting button Symbols from a non-Selenium example; refactoring from integers to Symbols and choosing an unsupported name.","solutions":["Use one of the documented Symbols: :left, :middle, :right, :back, :forward, :x1, :x2, :touch, :pen_contact, :pen_barrel.","Prefer the well-known aliases: :left (button 0), :middle (1), :right (2).","If you need a non-standard code, pass a non-negative Integer instead of a Symbol."],"exampleFix":"# before\ndriver.action.pointer_down(:center).perform # => ArgumentError: center is not a valid button!\n\n# after\ndriver.action.pointer_down(:middle).perform","handlingStrategy":"validation","validationCode":"BUTTONS = Selenium::WebDriver::Interactions::PointerPress::BUTTONS\nbutton = button.to_sym if button.is_a?(String)\nraise \"unsupported button: #{button}\" unless button.is_a?(Symbol) ? BUTTONS.key?(button) : button.is_a?(Integer)\n\ndriver.action.pointer_down(button).perform","typeGuard":"def valid_button?(b)\n  case b\n  when Symbol then Selenium::WebDriver::Interactions::PointerPress::BUTTONS.key?(b)\n  when Integer then !b.negative?\n  else false\n  end\nend","tryCatchPattern":null,"preventionTips":["Stick to :left/:middle/:right (and :back/:forward) instead of guessing names.","Validate Symbols against PointerPress::BUTTONS before passing."],"tags":["interactions","pointer-press","argument-validation","ruby"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}