开发者

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...


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.


Use Selenium's fireEvent on a mouseover event and then pause for your required hover time.


I have worked on similar one i used following see this might help you.

Using Selenium IDE.
1. Navigate to the required page.
2. Start selenium IDE and Get the Link target.
3. Change the Command to mouseOver Double click the the command in Selenium IDE.
4. It will Show the link wchich you needed.
5. Again Start recording and record the required Link.

When you Double click the mouseOver command it creates the simulation of mouse over through IDE and you can Use your mouse to record the popup link.

Thanks


I finally succeeded in getting Capybara + the Selenium driver to "hover" over an element. This is the code I'm using:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜