SeleniumHQ/selenium · error · ArgumentError

#{direction.inspect} is not a valid button direction

Error message

#{direction.inspect} is not a valid button direction

What it means

Raised as ArgumentError by PointerPress#assert_direction when the direction passed to PointerPress.new(source, direction, button, **) is not a key in DIRECTIONS. DIRECTIONS permits exactly :down (→ :pointerDown) and :up (→ :pointerUp).

Source

Thrown at rb/lib/selenium/webdriver/common/interactions/pointer_press.rb:78

        end

        def assert_button(button)
          case button
          when Symbol
            raise ArgumentError, "#{button} is not a valid button!" unless BUTTONS.key? button

            BUTTONS[button]
          when Integer
            raise ArgumentError, 'Button number cannot be negative!' if button.negative?

            button
          else
            raise TypeError, "button must be a positive integer or one of #{BUTTONS.keys}, not #{button.class}"
          end
        end

        def assert_direction(direction)
          raise ArgumentError, "#{direction.inspect} is not a valid button direction" unless DIRECTIONS.key? direction

          DIRECTIONS[direction]
        end
      end # PointerPress
    end # Interactions
  end # WebDriver
end # Selenium

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Use pointer_input.create_pointer_down / create_pointer_up so direction is set correctly.
  2. If constructing PointerPress directly, pass exactly :down or :up.

Example fix

# before
press = Selenium::WebDriver::Interactions::PointerPress.new(pointer, :press, :left) # => ArgumentError

# after
press = Selenium::WebDriver::Interactions::PointerPress.new(pointer, :down, :left)
Defensive patterns

Strategy: validation

Validate before calling

DIRECTIONS = Selenium::WebDriver::Interactions::PointerPress::DIRECTIONS
direction = direction.to_sym if direction.is_a?(String)
raise "unsupported direction: #{direction}" unless DIRECTIONS.key?(direction)

Type guard

def valid_direction?(d)
  Selenium::WebDriver::Interactions::PointerPress::DIRECTIONS.key?(d.is_a?(Symbol) ? d : d.to_sym)
end

Prevention

When it happens

Trigger: Constructing PointerPress with :press, :release, :click, 'down' (String), or :down? — anything outside {:down, :up}. Rarely user-facing because PointerInput#create_pointer_down / create_pointer_up hard-code the correct direction; only hit by direct PointerPress construction.

Common situations: Custom action-builder code or a port from another bindings language that names directions differently; passing a String instead of a Symbol.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/0f57056a70fd0bd9. Report an issue: GitHub.