1

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?

Yoni S
  • 36
  • 1
  • 7
  • 1
    Hi Yoni S, welcome to StackOverflow. Please provide us with a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) so we can see what your code is doing. – zwippie Jun 20 '19 at 22:23
  • I didn't added example because this was very general question and not about specific code. – Yoni S Jun 23 '19 at 09:07
  • @YoniS Please avoid asking "very general question"s because that is not the best way to use StackOverflow. As it stands your question is lacking several essential details that we need in order to give you a good answer. – Onorio Catenacci Jun 27 '19 at 13:10

2 Answers2

4

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

Ede
  • 103
  • 5
  • Thanks! It's exactly what I needed. what is the different between Wallaby.Browser.text() and Wallaby.Browser.page_source()? – Yoni S Jun 23 '19 at 09:26
  • There is a way to save the html with all the stile sources? – Yoni S Jun 23 '19 at 09:46
  • 1. @YoniS I've updated the answer, so your first comment should be answered. 2. I don't know of any build-in function in Wallaby to save the page with all assets. You would need to code this on your own or use another library. 3. Please check the question as accepted (like 7stud explained in her/his comment). – Ede Jun 24 '19 at 15:32
0

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.

7stud
  • 46,922
  • 14
  • 101
  • 127
  • That's not my problem, my problem was that an element that should be found and find function could not found it. But I found the problem, it happened because the program run to fast and the element still not loaded. – Yoni S Jun 23 '19 at 08:45
  • @YoniS, If Ede's answer helped you discover the problem, then you should click on the check mark to the left of Ede's answer, which will mark Ede's answer as accepted, notifying other people who look at your question that your question has been resolved. Also, clicking on the check mark will award Ede some points for answering your question. – 7stud Jun 23 '19 at 18:03