Capybara isn't finding select options #1242

Closed
kiddrew opened this Issue Feb 7, 2014 · 8 comments

Projects

None yet

6 participants

@kiddrew
kiddrew commented Feb 7, 2014

I'm using Capybara 2.2.1 with Rspec.

I have this code on my page:

<label for="question_category_id">Category</label>
<select id="question_category_id" name="question[category_id]">
  <option value="1">General</option>
</select>

And I've tried each of these:

select "General", from: "question_category_id"
select "General", from: "question[category_id]"
select "General", from: "Category"
page.select "General", from: "Category"

I get the same error every time:

Failure/Error: select "General", from: "Category"
Capybara::ElementNotFound:
  Unable to find option "General"

Everything I've read says that all of these should work. Am I doing something wrong?

@twalpole
Collaborator
twalpole commented Feb 8, 2014

I would guess that your option elements are being hidden through css or something along those lines. You can verify this by doing

select "General", from: "Category", visible: false

Also this question is better asked on the mailing list

@twalpole
Collaborator
twalpole commented Feb 8, 2014

One other possibility is you have multiple selects and have set Capybara.match = :first - although I don't think thats it since you have tried every different locator format for it, and you would have had to have multiple selects with the same id to keep seeing the issue

@kiddrew
kiddrew commented Feb 8, 2014

Thanks for the response. The select is definitely visible, but I tried visible: false just as a sanity check -- no dice. This is also the only select in the form, so that can't be it either.

I'll ask on the mailing list. Thanks.

@gillien
gillien commented Mar 13, 2014

I have the exact same problem with 2.2.1, and it was working perfectly before with 2.0.2. All my specs with a select failed now. @kiddrew where you able to fix that on our side?

@kiddrew
kiddrew commented Mar 13, 2014

I did get it working, but I can't remember at this point what I did...

@sseletskyy

select X, from: Y

X should be an option label, not an option value

@twalpole twalpole closed this Apr 3, 2014
@alexdesi
alexdesi commented Dec 7, 2015

That also happens when using Materializecss (with js: true), in that case is enough to pass the visible: false option (thanks @twalpole)

@wadson-qwiklabs

I just spent an afternoon on this issue, when doing a bit of debugging noticed that some of the fields were empty on the form, which led me to clone the development DB.

Rake db:test:prepare

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment