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
- Use pointer_input.create_pointer_down / create_pointer_up so direction is set correctly.
- 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
- Use create_pointer_down/create_pointer_up rather than constructing PointerPress with a direction.
- If constructing directly, pass exactly :down or :up.
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
- #{source.type} is not a valid input type
- #{button} is not a valid button!
- Button number cannot be negative!
- #{type.inspect} is not a valid key subtype
- #{action.inspect} is not a valid action
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/0f57056a70fd0bd9.
Report an issue: GitHub.