简体   繁体   中英

Elixir Hound wait for page to load

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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