Can't fill_in a text field with wallaby

Hi all,

I am trying to fill in a text field with wallaby, with no luck.
This is the test snippet I am using:

session
|> visit("/some/path/")
|> find(css("#location-search"))
|> fill_in(text_field("location-search"), with: "Some text")
# |> fill_in(text_field("Location"), with: "Some text") # tried with label
# |> fill_in(text_field("location[search]"), with: "Some text") # tried with name

Please note that if I comment out the fill_in... line the test passes, so the element with id location-search is correctly found.

The relevant template part is

<label for="location-search"><%= dgettext("oha", "Location") %></label>
<input
  id="location-search"
  name="location[search]"
  type="text"
  placeholder="E.g. Stranzenberggasse 5"
  class="col-span-3"
  data-location
  onkeypress="return event.key != 'Enter';"
/>

The error I get is

...
** (Wallaby.QueryError) Expected to find 1 visible text input or textarea 'location-search', but 0 visible text inputs or textareas were found.
...

Any idea what I am doing wrong here?

Thank you

Self answering here.

When you find elements in the page, you are scoped to that element, that’s why the subsequent fill_in doesn’t succed.

What I am doing now is to perform the find on the form element, and then fill_in the text field.

1 Like