I am trying with Capybara to use the Select Method. I tried all the solutions included, especially those from this Stackoverflow Discussion.
I have the following select done with the country_select gem. This is the html.erb code from the form:
<%= f.country_select(:country, {include_blank: 'Select a country', selected: "Select a country"}, {class: 'form-control', :id => "country_select"}) %>
The html from the browser looks like this:
<select class="form-control" id="country_select" name="user[country]"><option value="">Select a country</option>
<option value="AF">Afghanistan</option>
<option value="AX">Ă…land Islands</option>
<option value="AL">Albania</option>
other staff...
When I debug the select method from the Capybara GEM file actions.rb row 183 (where I set a breakpoint), the output is correct.
def select(value, options={})
binding.pry
if options.has_key?(:from)
from = options.delete(:from)
find(:select, from, options).find(:option, value, options).select_option
else
find(:option, value, options).select_option
end
end
So the line:
find(:select, from, options).find(:option, value, options)
returns
=> #<Capybara::Node::Element tag="option" path="/html/body/div/div[2]/div/div/div/div/div/form/div[4]/select/option[2]">
Which is the correct select option. As you can see the option[2]
is Afganistan, but it looks like .select_option
does not work.
I think Capybara is not opening the select box before selecting the field. I have capybara (2.13.0) and rails 5.0.2
Thanks a lot Fabrizio Bertoglio