Wallaby Elixir cannot find element

Hello,
i’m trying to automate some core regression tests but i’m a newbie at this . my login is working but i cannot click on on the first of the 5 css elements selected . see my script and also the html elment. hope i’ve provide enough info. Any good general info also appreciated . i’m finding my progress very slow .

@tag runnable: true
test “select a practice --core test”, %{session: session} do
login(session)
|> assert_has(css(".intro__title", text: “Scrum Essentials”))
|> IO.inspect() #
#|> assert_has(css(".practice__title", text: “Scrum Essentials”))
#|> find( css(".practice__title", count: nil, minimum: 0)).
|> find(css(".practice__title", count: 5))
#|> List.first
|> Enum.at(0)
|> double_click()
|> IO.inspect() # notice this has a wallaby element struct as well as session
# i think we have to find a way to switch to the element and not the #session ?
#|> assert_has(css(".practice__title"))
#|> assert_has(css(".practice__title", text: “Scrum Essentials”))
|> click(css(".practice__title"))
#|> click((“Executive Scrum Essentials”))
#|> click(link(“Executive Scrum Essentials”))
#|> click(link(“Scrum is a Framework”))
:timer.sleep(9000) # mouse hasn’t move to the element we want to click on
end
message from the console

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

note i can find the css selector in chrome dev tools $$(".practice__title")
10) [h2.practice__title, h2.practice__title, h2.practice__title, h2.practice__title, h2.practice__title, h2.practice__title, h2.practice__title, h2.practice__title, h2.prac

1 Like

find/2 returns the found element(s), which allows you to be able to click it.

But at that point you have that element, not the session. So later when you try to find that element again, you are searching for it within itself, so it won’t be found.

You can use find/3 which takes a callback and returns the session, or you can start a new expression after you click and use the session again.

1 Like

Thanks for the explanation, i usnderstnad at a conceptual level the problem i’m searching in the element not the form so callback with the form

looking at your github find/3 example here I cobbled together something that compiles and runs

but i still get
** (Wallaby.QueryError) Expected to find 1, visible element that matched the css ‘.practice__title’ but 0, visible elements were found

here is the code

@tag runnable: true
test “select a practice --core test”, %{session: session} do
login(session)
|> assert_has(css(".intro__title", text: “Scrum Essentials”))
|>find(css(".practice__title", count: :any), fn(form) →
form
#|> List.first

  |> Enum.at(4)
  |> IO.inspect()
  |> click(css(".practice__title"))
end)
|> IO.inspect()
:timer.sleep(9000)  # mouse hasn't move to the element we want to click on

end

i don’t think i’m still grokking it , feel free to suggest pseudo or straigh code changes with explanations if you are so inclined/obliged. Well aware this is not your level . trying to get to a level of independence but it’s burning the clock. thanks

So trying some things (same code base) I tried these two:

|> find(css(".practice__title"), fn form ->

.. and got

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

Docs suggest a count of :any to handle that.

|> find(css(".practice__title", count: :any), fn form ->

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

The page is quite inactive at this stage so I don’t expect this to be something mysterious there.

Worked around it with a :first-child in the CSS selector which makes it pass, but the API/docs threw me for a loop with what I thought would work there.

@tag runnable: true
test “select a practice --core test”, %{session: session} do
login(session)
|> assert_has(css(".intro__title", text: “Scrum Essentials”))
|> find(css(".practice__title", count: :any), fn (form) ->
  form
  |> Enum.at(4)
  |> IO.inspect()
  |> click(css(".practice__title"))
end)
|> IO.inspect()
:timer.sleep(9000)  # mouse hasn't move to the element we want to click on
end

The callback you pass to find/3 will return the element(s) that it finds. In your case, it looks like it returns 5 elements that have the class .practice__title.

So in your example, you have the element that you seem to want to click, but then you attempt to find that element again, inside of itself, which it obviously isn’t going to find.

I think what you want is this, which doesn’t require a find.

@tag runnable: true
test “select a practice --core test”, %{session: session} do
  login(session)
  |> assert_has(css(".intro__title", text: “Scrum Essentials”))
  |> click(css(".practice__title", at: 4))
end
1 Like