Ruby on rails 选择:水豚::不明确:不明确匹配,找到2个元素匹配可见选项

Ruby on rails 选择:水豚::不明确:不明确匹配,找到2个元素匹配可见选项,ruby-on-rails,selenium-webdriver,rspec,capybara,Ruby On Rails,Selenium Webdriver,Rspec,Capybara,我正试图从列表中选择一个国家。确实有两个项目同名 select user_info.company_country, from: 'Company country' HTML: 错误: Capybara::Ambiguous: Ambiguous match, found 2 elements matching visible option "United States of America" within #<Capybara::Node::Element tag="selec

我正试图从列表中选择一个国家。确实有两个项目同名

select user_info.company_country, from: 'Company country'
HTML:

错误:

 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">
似乎没有任何选项可以选择第一个选项


和往常一样,水豚有多种方法来做你想做的事。您应该能够通过手动查找所需的选项,然后在其上调用select_选项来完成此操作

或者可能通过将match::first选项传递给select,但实际上还没有尝试过,但是从代码来看,它应该可以工作,因为选项在两个查找之间共享,select实际执行

select user_info.company_country, from: 'Company country', match: :first

哇,谢谢,我正要编辑并说firstoption[value='{user_info.company_country}'。单击不起作用。它实际上不会选择国家或提交。但是第一个选项[value={user\u info.company\u country}].选择选项有效!选择user_info.company_country,from:'company country',match::first也可以。尽管我对使用未记录的功能有所保留。@克洛伊可以随意使用,我不会改变这一点
find('#user_company_country option[value="United States of America"]', match: :first).select_option
first(:option, 'United States of America').select_option
select user_info.company_country, from: 'Company country', match: :first