Capybara selenium driver hovering element

In the application I'm testing, some elements are hidden initially. They will be displayed via CSS when hovering over a single element:

.thread_options{ display: none; } .btn_thread_options:hover .thread_options{ display: inline; } 

Hovering over the .btn_thread_options element displays some links that I want to click on Capybara. Trying to click them without any action using click_link "Send Response" gives me an error:

 Failure/Error: click_link("Send Response") Selenium::WebDriver::Error::ElementNotVisibleError: Element is not currently visible and so may not be interacted with 

Trying to use other ways to click on it, for example

 page.execute_script("$('.btn_thread_options').trigger('mouseover')") 

Doesn't work (same result).

Do not click an element first to try to make it shove:

 page.find(".btn_thread_options").click 

Is there a way to make this work correctly?

+4
source share
3 answers

This has been added to Capybara:

 find(:css, "#menu").hover 
+6
source

You can try to display the element directly rather than mousing.

 page.execute_script("$('.thread_options').css('display','inline')") 

It is also possible to explore the ignore_hidden_elements setting. The default value is false, but you may have set it to true.

Or instead of displaying no, set the field to a large negative value.

 /* Move the element off the screen */ .thread_options{ margin: -9999px 0 -9999px 0; } /* Set the desired display margins .btn_thread_options:hover .thread_options{ margin: 10px 0 10px 0; } 
+3
source

I found a way to simulate mouse hover using the Capybara + Selenium driver. This code works for me:

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

Source: https://habr.com/ru/post/1387082/


All Articles