Hover over capybara

I have a button on the page that appears only when it hangs over a certain element. But I can’t figure out how to emulate this, and then click on the link so that I can check it with Cucumbers using Capybara and Selenium.

+8
selenium mouseevent capybara
source share
2 answers

This may require a custom defined step, for example:

When /^I click "([^"]*)" inside element "([^"]*)"$/ do |button, element_name| 

Inside you write something like:

 begin evaluate_script("$('#{element_name}').trigger('mouseover')") rescue Capybara::NotSupportedByDriverError end 

And then you press the button you want :)

+5
source share

I found a way to simulate mouse hover using the Capybara + Selenium driver. Try this code:

 module Capybara module Node class Element def hover @session.driver.browser.action.move_to(self.native).perform end end end end 
0
source share

All Articles