I'm trying to select a country from a list. There are indeed 2 items with the same name.
select user_info.company_country, from: 'Company country'
HTML:
<select class="" name="user[company_country]" id="user_company_country">
<option value=""></option>
<option value="United States of America">United States of America</option>
<option value="Afghanistan">Afghanistan</option>
... 200+ countries
<option value="United States of America">United States of America</option>
<option value="Uruguay">Uruguay</option>
Error:
Capybara::Ambiguous:
Ambiguous match, found 2 elements matching visible option "United States of America" within #<Capybara::Node::Element tag="select" path="/html/body/div[3]/section/div/div/div/form/div/div[8]/select">
There doesn't appear to be any options to choose the first option.
https://www.rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Actions#select-instance_method
As usual with Capybara there are multiple ways to do what you want. You should be able to do it by manually finding the option you want and then calling select_option
on it
find('#user_company_country option[value="United States of America"]', match: :first).select_option
or
first(:option, 'United States of America').select_option
or possibly by passing the match: :first
option to select (haven't actually tried that, but from the code it should work since the options are shared between the two finds select
actually performs)
select user_info.company_country, from: 'Company country', match: :first
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With