Hover Implementation Selenium 28 Apr 2011
Tags: hover, selenium, tests

While I was learning how to add tests using Capybara, Selenium and Cucumber, I encountered a roadblock when I tried to click on a link that is initially hidden and will show on hover. Selenium supports this but I can't make it work.

After some more documentation readings (most about Capybara sessions), I figured out that one way of triggering the hover effect is by manually running a script. Since hover is not really a js event, you can't just call $('element').hover() so instead, just modify the element's css.

ruby
When /^I hover over "([^"]*)"$/ do |selector|
  page.execute_script("$('#{selector}').css({'display':'inline'});")
end