为什么看起来像水豚“等待页面加载”?计时器适用于匹配器,但不适用于查找器? [英] Why does it seem like the Capybara "wait for page to load" timer works for matchers but not finders?
问题描述
我目前正在运行一项测试,检查特定元素,然后对其进行处理。该元素需要花费一些时间才能完成javascript的播放,但是在计时器内,我已经设置了水豚。
I'm currently running a test that checks for a specific element and then do some stuff to it. The element takes a little for the javascript to finish kicking in, but well within the timer I've got Capybara set for.
出于某种原因
assert session.has_xpath?(xpath_route)
工作正常,但
assert link=session.first(:xpath, xpath_route)
失败,表示找不到元素。很快-在等待计时器用完之前很久。
fails, saying it could not find the element. And quickly - long before the wait timer would run out.
我只能假设这意味着计时器仅适用于匹配器,而不是查找器,这很好,但是如何我强迫它继续查找,直到找到我要查找的元素为止。
I can only assume this means the timer only applies to matchers, not finders, which is fine, but how can I force it to keep looking until it finds the element I'm looking for?
推荐答案
假设超时确实是正确的,您是正确的首先使用
时不适用。但是您可以使用 wait_until
方法,该方法将一直重试直到超时到期或该块返回真实值为止,因此:
You are correct assuming that the timeout does not apply when using first
. But you can use the wait_until
method, which will keep retrying until either the timeout expires, or the block returns something truthy, so:
page.wait_until() do
session.first(:xpath, xpath_route)
end
这篇关于为什么看起来像水豚“等待页面加载”?计时器适用于匹配器,但不适用于查找器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!