Reputation: 56
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?
Upvotes: 3
Views: 5199
Reputation: 123
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
Upvotes: 6
Reputation: 48629
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 a p 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.
Upvotes: 0