Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Capybara and Selenium to hover over an element

I have a link on a page which only appears when hovering over a certain element. But I can't figure out how to emulate this and then click on the link so I can cucumber test it using Capybara and Selenium.

Anyone know how to do this? I've tried executing javascript and and also trying to talk to the selenium driver directly but so far I'm not having much luck...

like image 417
Ganesh Shankar Avatar asked Jun 17 '11 06:06

Ganesh Shankar


1 Answers

This question is a few years old, so the answer might have changed. In newer versions of Capybara there are a few different ways to do it, depending on the driver you're using.

For selenium, you can execute javascript:

page.execute_script '$("#element").trigger("mouseover")'

Newer versions of selenium-webdriver support a hover method:

find('#element').hover

For capybara-webkit, the driver supports triggering events on the element:

find('#element').trigger(:mouseover)

I originally found the answer to this question from here and here.

like image 69
Andrew Avatar answered Sep 30 '22 20:09

Andrew