ijdickinson

ijdickinson

Finding the value of a select option element using Wallaby.Query

I’m writing a Wallaby test for a select element that looks something like this:

<select id="status-select" name="status">
   <option selected="" value="b9259ffd-a2de-488f-85f0-567d1e9a7159">new</option>  
   <option value="f56f5249-0920-4747-8e89-e8b07ba1a5e8">assigned</option>
</select>

The value attributes on the options are auto-assigned each time by the back-end system. So in order to be able to call Wallaby.Browser.set_value/3, I need to first query the page to find the current value for the option. My code to do that is:

value_fixture = Browser.find(
  session, 
  Query.css("#status-select > option:nth-child(2)", visible: false)
)
|> Element.attr("value")

If I execute the query expression in the browser console with a document.querySelectorAll(), it finds the right element for me.

image

But Wallaby doesn’t:

** (Wallaby.QueryError) Expected to find 1 invisible element that matched
the css ‘#status-select > option:nth-child(2)’, but 0 invisible elements were found.

Is there some other way to query the options of a select using Wallaby that I should be using?

Marked As Solved

ijdickinson

ijdickinson

Argh. PEBCaK!

My fixture set-up had a bug, so the page that Wallaby was seeing didn’t actually have the set of statuses it should have have, and so the :nth-child() sub-expression was failing.

Doh.

Where Next?

Popular in Questions Top

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
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
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
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; someth...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
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
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42842 311
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
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
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
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 31107 143
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
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

We're in Beta

About us Mission Statement