Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't fill in any hidden elements in Capybara when ignore_hidden_elements is true

I'm writing some feature tests using Capybara, for pages that involve lots of javascript refreshes (the url will stay the same when a user clicks a "continue" button, but hidden content will be shown, and shown content will be hidden, so that there is a HUGE amount of text/selectors/etc at any given point "on" the page but hidden from the user).

To test this functionality, I want Capybara's ignore_hidden_elements config option to be true, because that best represents the user experience.

But there are also some jQuery plugins on the page that use fancy graphics to fill in basic HTML elements that are hidden, and I would like to use Capybara to just select the correct values for those elements, rather than trying to use Javascript to manually simulate a user interacting with the element.

In particular, I am trying to test Select boxes that are set to display:none and are filled by a jQuery plugin when a user interacts with them. I'd love to be able to do this:

select('value', from: 'select_box')

but the select box is hidden.

So I tried this:

select('value', from: 'select_box', visible: false)

but that didn't work either. I'm loath to turn ignore_hidden_elements to false, because that more poorly simulates a user, and I'd have to go back and add "visible: true" to many many lines of testing.

Any idea how to do this? Is there an option that more neatly cancels out ignore_hidden_elements?

EDIT -- Following Andrey's response, I turned ignore_hidden_elements to false, and then did the same capybara select test as before:

select 'value', from: 'select_box_id'

and, like magic, it worked. When I again change ignore_hidden_elements to true and try this line:

select 'value', from: 'select_box_id', visible: false

I get this error:

Failure/Error: select 'value', from: 'select_box_id', visible: false
     Capybara::ElementNotFound:
       Unable to find select box "select_box_id"

Any chance this isn't a bug? Should I report it?

like image 301
Sasha Avatar asked Nov 13 '22 05:11

Sasha


1 Answers

It's a bug in Capybara 2.0.x. Here is a test case that is reproducible in 2.0.x but not in 2.1.

But Capybara-Webkit maintainers haven't yet released Capybara 2.1-compatible version.

Possible solutions for you:

  • use Capybara 2.1-compatible driver
  • use Capybara-Webkit from master branch on github
  • don't try to interact with invisible elements (it doesn't work in Selenium so I believe possibility of interaction should be considered a bug in Capybara-Webkit)
like image 172
Andrei Botalov Avatar answered Nov 14 '22 22:11

Andrei Botalov