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

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
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
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
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

Other popular topics Top

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
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New

We're in Beta

About us Mission Statement