wait_until block is giving time out error

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 21:27:33

问题


This is the code which is failing for me.

link(:continue, :text => 'Continue Shopping')

def verify_cart
    wait_until(60) do
      continue_element.visible?
    end
  end

To make it work I have tried solutions here: Inconsistently getting error (Watir::Wait::TimeoutError) and Timeout::Error in Rails application using Watir but none worked for me.

I have also tried by increasing the time.

Then I tried by increasing the at implicit wait from 3 seconds to 20 seconds and instead of using wait_until block I simply used .visible? and it worked.

link(:continue, :text => 'Continue Shopping')

continue_element.visible?

 #def verify_cart
 #   wait_until(60) do
 #     continue_element.visible?
 #   end
 # end 

Now question is when element was there why wait_until kept on failing?


回答1:


continue_element.visible? 

is not going to raise an error, it is just going to return a boolean. It sounds like this element doesn't actually end up visible, and this would still raise the error regardless of the implicit wait:

raise unless continue_element.visible?

Also, a better pattern for this is:

continue.wait_until_present 

or

continue.when_present.click 

.present? just means .exists? && .visible? which is actually what you want, and this pattern will give you a better error message.



来源:https://stackoverflow.com/questions/29450250/wait-until-block-is-giving-time-out-error

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