Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capybara selenium driver, hovering an element

The app I'm testing has some elements hidden initially. They will display via CSS when hovering over a separate element:

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

When you hover over the .btn_thread_options element, some links are displayed that I want Capybara to click on. Attempting to click these without doing anything using click_link "Send Response" gives me the 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 of clicking it like

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

Doesn't work either (same result).

Nor does clicking the item first to try to force it to be moused over:

page.find(".btn_thread_options").click

Is there any way to get this to work correctly?

like image 906
nzifnab Avatar asked Dec 28 '22 09:12

nzifnab


2 Answers

This has been added to Capybara:

find(:css, "#menu").hover
like image 63
mikewilliamson Avatar answered Dec 30 '22 07:12

mikewilliamson


You could try displaying the element directly rather than mousing over.

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

Maybe also investigate the setting of ignore_hidden_elements. It defaults to false, but perhaps you have it set to true.

Or instead of display none, set the margin 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;
}
like image 37
michaeltwofish Avatar answered Dec 30 '22 08:12

michaeltwofish