Capybara/Selenium: Hovers and drags spend 250 ms on every pointer move

Posted . Visible to the public.

Selenium's Actions API animates every pointer move to make it somewhat realistic. Capybara uses this for

  • hover
  • drag_to
  • right_click
  • double_click
  • click with an offset (x:, y:) or modifier keys

Each of these waits 250 ms for a test-only animation which we usually try to disable anyway. You can make it instant if you want:

# spec/support/instant_pointer_moves.rb

if Gem::Version.new(Capybara::VERSION) > Gem::Version.new('3.40.0')
  raise 'Please check if Capybara::Selenium::Node#browser_action still builds every action chain (InstantPointerMoves)'
end

module InstantPointerMoves

  private

  # Capybara builds every action chain here
  def browser_action
    super.tap { |action| action.default_move_duration = 0 }
  end

end

Capybara::Selenium::Node.prepend(InstantPointerMoves)
Profile picture of Michael Leimstädtner
Michael Leimstädtner
Last edit
Michael Leimstädtner
License
Source code in this card is licensed under the MIT License.
Posted by Michael Leimstädtner to makandra dev (2026-10-19 11:58)