padjo
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
Most Liked
mhanberg
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.
mhanberg
@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








