问题
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