Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 832
artemave Avatar asked Jan 19 '23 15:01

artemave


1 Answers

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? }
like image 196
nowk Avatar answered Feb 01 '23 14:02

nowk