padjo

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

mhanberg

Expert LSP Core Team

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

mhanberg

Expert LSP Core Team
@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

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement