Pradeep Pradeep - 5 months ago 28
Ruby Question

How to add a wait method to wait until a specific element is loaded in ruby+Cucumber2.0

I have a problem while testing my cases on browser stack. The problem am facing is inconsistently reproduced.

To make my code wait until an element is loaded am using as below:

gift_no_btn1 = Capybara.find('giftingNoButton')

The problem here is that the screen is stuck in the other module where my intended element is not loaded and hence my script fails. I have read that find() method is replaced of wait_untill method in Capybara 2.0.


Capybaras find methods will wait up to Capybara.default_max_wait_time seconds for a matching element to appear. If they are not waiting long enough either increase that setting or override it for a specific find with the :wait option like

page.find :css, 'CSS selector for the element', wait: 10

which will wait up to 10 seconds for the element to exist. In your example you're passing a CSS selector of 'giftingNoButton' which isn't really valid unless you're using custom elements. You probably want '#giftingNoButton' (find id matching) or '.giftingNoButton' (class matching)