Elixir Hound等待页面加载 [英] Elixir Hound wait for page to load

查看:83
本文介绍了Elixir Hound等待页面加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在提交一个登录表单,然后尝试使用elixir / hound捕获HTML。提交后,我运行 page_source 却一无所获。如果我等待一秒钟(页面完成加载),那么我会得到html。

I'm submitting a login form and trying to capture the HTML afterwards using elixir / hound. After submitting I run page_source and get nothing. If I wait for a second (for the page to finish loading) then I get back the html.

有没有办法让猎犬等到页面完成加载?

Is there a way to make hound wait till the page is finished loading?

我目前正在做::timer.sleep(2000)作为一种变通方法,希望能更好方法:/

I'm currently doing: :timer.sleep(2000) as a work around, hoping for a better way :/

推荐答案

这就是我的工作:

创建一个每100毫秒重复检查测试条件的函数,在这种情况下,我正在等待使用
visible_page_text

Create a function that repeatedly checks for a test condition every 100ms, in this case I'm waiting for particular text to appear by using visible_page_text

@tag timeout: 6000
test "My Test" do
  assert wait_for(fn -> Regex.match?(~r/Success/, visible_page_text()) end)
end

def wait_for(func) do
  :timer.sleep(100)
  case func.() do
    true -> true
    false -> wait_for(func)
  end
end

这篇关于Elixir Hound等待页面加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆