Warm tip: This article is reproduced from serverfault.com, please click

capybara, selenium interact with hidden or display: none css properties

发布于 2011-10-16 14:16:49

I'm using similar construction:

<div class="edit" style="visibility: hidden;">
  <a href="some_path" id="edit_item">Edit</a>
</div>

Then I hover mouse this element become visible, but I have difficult to interact this actions with tests(using cucumber, capybara, selenium).

I get an error

Element is not currently visible and so may not be interacted with (Selenium::WebDriver::Error::ElementNotDisplayedError)

I tried to use Element.trigger(event) with mouseover, but it doesn't work in selenium... How I can interact with this element?

Questioner
Mikhail Grishko
Viewed
1
Mikhail Grishko 2011-10-18 03:04:08

I solved this problem using execute_script from capybara:

When /^I hover element "([^""]*)"(?: within "([^""]*)")?$/ do |id,selector|
  with_scope(selector) do
    page.execute_script("$('#{id}').mouseover();")
  end
end

When /^I click in hide element "([^""]*)"(?: within "([^""]*)")?$/ do |id,selector|
  with_scope(selector) do
    page.execute_script("$('#{id}').click();")
  end
end

but this solution doesn't work with css - display: none;