Elixir Hound 等待页面加载 [英] Elixir Hound wait for page to load
问题描述
我正在提交一个登录表单,然后尝试使用 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.
有没有办法让 hound 等到页面加载完成?
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屋!