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.

Last Post!

ijdickinson

ijdickinson

One final note for future reference: although it’s not (afaics), mentioned in the docs, but when setting the value of a select element, Wallaby.Browser.set_value/3 needs the text of the option to select, not the value.

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
I would like to know what is the best IDE for elixir development?
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
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
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 44532 311
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

We're in Beta

About us Mission Statement