简体   繁体   English

Elixir Hound等待页面加载

[英]Elixir Hound wait for page to load

I'm submitting a login form and trying to capture the HTML afterwards using elixir / hound. 我正在提交登录表单并尝试使用elixir / hound捕获HTML。 After submitting I run page_source and get nothing. 提交后我运行page_source并得不到任何结果。 If I wait for a second (for the page to finish loading) then I get back the html. 如果我等待一秒钟(页面完成加载),那么我回到html。

Is there a way to make hound wait till the page is finished loading? 有没有办法让猎犬等到页面完成加载?

I'm currently doing: :timer.sleep(2000) as a work around, hoping for a better way :/ 我目前正在做:: :timer.sleep(2000)作为一种解决方法,希望有更好的方法:/

This is what I do: 这就是我做的:

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 创建一个每隔100ms重复检查一次测试条件的函数,在这种情况下,我正在等待使用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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM