简体   繁体   中英

How to get html page in wallaby

I try to run fin function but for some reason I get back nil. The item I search for have to be there, how can I get the html to see what went wrong?

I have two helper functions that receive the wallaby session.

The first prints the visible text to STDOUT:

  def print_page_text(session) do
    session |> Wallaby.Browser.text() |> IO.inspect()
    session
  end

The second function prints the complete HTML page source to STDOUT:

  def print_page_source(session) do
    session |> Wallaby.Browser.page_source() |> IO.inspect()
    session
  end

By returning the session these functions can be used between the usual wallaby queries/assertions:

session
|> visit("/example/page")
|> print_page_text()
|> assert_text("Hello World!")

Another helpful function is Wallaby.Browser.take_screenshot/2

I don't know if this is your problem or not, but when I tried wallaby on this html:

<p class="results"><div class="green">That's all folks!</div></p>

with this find() :

find(css(".results", count: 1))

I got the error:

** (Wallaby.QueryError) Expected to find 1, visible element that matched the css '.results' but 0, visible elements were found.

But, if I change the html to this:

<div class="results"><span class="green">That's all folks!</span></div>

and I use the same find() (which by the way does not return a list, so don't follow that with List.first() ), then wallaby does find the element. According to the html5 spec, you can't put a div tag inside ap tag, and the opening div tag will cause a browser to close the p tag , like this:

                   HERE
                    |
                    V
<p class="results"></p><div class="green">That's all folks!</div></p>

I don't think wallaby is able to parse the illegal html and find the p tag. You might try running your html through an html validator before trying wallaby on it.

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