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?
I'm currently doing: :timer.sleep(2000)
as a work around, hoping for a better way :/
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
@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