How to emulate mouse hover with Capybara

Basically, what I'm trying to do is click on a button that becomes visible when hovering another element (its parent).

I have tried to use trigger.('mouseover') on the parent of the hidden button, but that doesn't seem to work.

Here's a code snippet from the spec:

 # label[for ... ] -> the parent element
 # le hidden button
 # some <li> on a list that drops down when clicking the hidden button    
 click_on("Edit department")

And the error ...

 Failure/Error: click_on("Edit department")
 Element is not currently visible and so may not be interacted with

I would like to know how can I make the .actions button visible on the page, in order to click it afterwards.

Any help would be much appreciated.


Capybara provides Element#hover method from version 2.1:


This method is implemented in Capybara::Selenium::Driver in almost the same way as in @AlexD's answer.

Note that to use #hover in Selenium it's usually better to turn native events on:

Capybara.register_driver :selenium do |app|
  profile =
  profile.native_events = true, :browser => :firefox, profile: profile)

Alex described the solution of such problems in his blog: check it out

RSpec.configure do |config|
  # ...
  Capybara.javascript_driver = :webkit


I found a way to simulate "mouse hover" using Capybara + the Selenium driver:

module Capybara
  module Node
    class Element
      def hover

Using Capybara + Selenium it is possible to use "hover" with this command:


Need Your Help

"please check gdb is codesigned - see taskgated(8)" - How to get gdb installed with homebrew code signed?

c++ eclipse macos gdb homebrew

I'm under osx 10.8.4 and have installed gdb 7.5.1 with homebrew (motivation get a new gdb with new features such as --with-python etc... )

Xcode 5 & Asset Catalog: How to reference the LaunchImage?

ios xcode ios7 xcode5 asset-catalog

I am using Xcode 5's Asset Catalog, and I would like to use my LaunchImage as the background image of my home view (a pretty common practice to make the transition from 'loading' to 'loaded' look s...