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.

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
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
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.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









