问题描述
这是我失败的代码。
解决方案<$ p $ p> continue_element.visible?
不会引发错误,它只是要返回一个布尔值。它听起来像这个元素实际上并没有结束可见,这仍然会引起错误,无论隐式等待:
提高除非continue_element.visible?
此外,更好的模式是:
continue.wait_until_present
或
continue.when_present.click
.present?只是指 .exists?&& .visible?这其实是你想要的,这个模式会给你一个更好的错误信息。
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?
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.
这篇关于wait_until块给出超时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!