Why does it seem like the Capybara “wait for page

2019-05-09 08:10发布

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?

标签: ruby capybara
1条回答
女痞
2楼-- · 2019-05-09 08:18

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
查看更多
登录 后发表回答