artemave
artemave

Reputation: 6946

Capybara/selenium: wait for element to become hidden

I need to wait for loading bar (div#loading) to disappear (become display: none) in a cucumber step. I'd expect the following to do the trick

find('#loading').should_not be_visible

But it doesn't seem to be waiting. Any ideas how to achieve that?

Upvotes: 4

Views: 4127

Answers (1)

nowk
nowk

Reputation: 33171

You will want to use the wait_until to wait for your condition to be met.

wait_until { !page.evaluate_script(%{$('#loading').is(':visible')}) } 

There might be a better wait to check for visibility, but last time I checked page.has_no_css does not work with things like :visible.

(Update) Though has_css does not see selectors like :visible, Capybara::Node::Element does have some methods to make the above a bit prettier.

wait_until { !find("#loading").visible? }

Upvotes: 9

Related Questions