mardi 20 janvier 2015

Capybara can't find elements on dropdown lists

I'm trying to troubleshoot a feature spec I'm writing to learn Rails & testing. It's an edit_spec for a Rails 4 app. I'm using RSpec and Capybara.


The Problem: Capybara can not find elements from two drop down lists on a form. Here's the relevant parts of my form's source code:



<div class="field">
<label for="appointment_member_id">Member</label><br>
<select id="appointment_member_id" name="appointment[member_id]">
<option value="1">Callis Callis</option>
<option value="2">Rachale Rachale</option>
<option value="3">Hal Hal</option>
<option value="4">Kallis Kallis</option>
<option value="5">Earle Earle</option>
<option value="6">Rudy Rudy</option></select>
</div>
<div class="field">
<label for="appointment_trainer_id">Trainer</label><br>
<select id="appointment_trainer_id"
name="appointment[trainer_id]"> <option value="1">Jacob Jacob</option>
<option value="2">Michele Michele</option>
<option value="3">Alex Alex</option>
<option value="4">Yanni Yanni</option>
<option value="5">Upton Upton</option>
<option value="6">Willham Willham</option></select>
</div>


In my edit_spec, I tried using "option value" and "select id" to get Capybara to select names from the drop-down lists:



select('4', :from => 'appointment_member_id')
select('2', :from => 'appointment_trainer_id')


The result is a Capybara::ElementNotFound error. Here's the full text of the error message:


updates an appointment successfully with corrected information (FAILED - 1)


Failures:



1) Editing appointments updates an appointment successfully with corrected information
Failure/Error: select('4', :from => 'appointment_member_id')
Capybara::ElementNotFound:
Unable to find option "4"


I researched the issue and documentation for Capabara, and also a Stackoverflow post with similar problem. The poster solved the issue, but couldn't recall how he did it. I'm baffled as to why Capabara can't find the member and trainer from the drop down list? The option values and names appear to be visible on the form. What am I missing? I appreciate any help!


Aucun commentaire:

Enregistrer un commentaire