padjo

padjo

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

First 5 of 5 Posts Switch mode

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.

padjo

padjo OP

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
https://github.com/elixir-wallaby/wallaby

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

lawik

lawik

Nerves Core Team

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.

lawik

lawik

Nerves Core Team

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.

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
— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement