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

﹥>﹥吖頭↗ 提交于 2019-12-11 05:06:37

问题


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')
gift_no_btn1.click

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.


回答1:


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)



来源:https://stackoverflow.com/questions/39859291/how-to-add-a-wait-method-to-wait-until-a-specific-element-is-loaded-in-rubycucu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!