为什么水豚看起来像是“等待页面加载”?计时器适用于匹配者但不适用于查找者?
我目前正在运行一个测试,检查特定元素,然后对其执行一些操作。该元素需要一点时间才能让 JavaScript 完成启动,但在我为 Capybara 设置的计时器内。
由于某种原因,
assert session.has_xpath?(xpath_route)
工作正常,但
assert link=session.first(:xpath, xpath_route)
失败,说找不到该元素。而且速度很快——早在等待计时器用完之前。
我只能假设这意味着计时器仅适用于匹配器,而不适用于查找器,这很好,但是我如何强制它继续查找,直到找到我正在查找的元素?
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.
For some reason
assert session.has_xpath?(xpath_route)
works fine, but
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设使用
first
时超时不适用,您是正确的。但是您可以使用 wait_until 方法,该方法将不断重试,直到超时到期或块返回真实值,因此:You are correct assuming that the timeout does not apply when using
first
. But you can use thewait_until
method, which will keep retrying until either the timeout expires, or the block returns something truthy, so: