4

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 :/

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
newUserNameHere
  • 17,348
  • 18
  • 49
  • 79

1 Answers1

2

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
deadkarma
  • 3,144
  • 2
  • 17
  • 19