0
我試圖重構一段舊的測試。下面的代碼:如何使用帶水路的水豚從元素集中拉項目
describe "translation result", :js => true do
it "translations should be shown as links to translations in second way" do
visit '/'
fill_in('query-field', :with => 'kOŃ')
click_button('search-button')
sleep(7)
page.all(:css, '.result a').size.should eq(2)
page.find('.result a').text.should == 'horse'
end
end
回報以下信息:
1) translation result translations should be shown as links to translations in second way
Failure/Error: page.find('.result a').text.should == 'horse'
Capybara::Ambiguous:
Ambiguous match, found 2 elements matching css ".result a"
# ./spec/integration/result_spec.rb:12:in `block (2 levels) in <top (required)>'
我試圖讓從什麼是「發現法」在描述塊返回的元素。這意味着我試圖做到這一點,如下圖所示:
page.find('.result a').first.text.should == 'horse'
或
page.find('.result a')[0].text.should == 'horse'
我這樣做是因爲我想,當我有兩個元素,然後我可以讓他們中的一個。你認爲我的邏輯是正確的嗎?如何解決問題。與代碼回購是在這裏:https://github.com/mtczerwinski/dict-app
你嘗試'頁。 all(:css,'.result a')。first.text.should =='horse''? – phoet
'page.should have_css('。result a',text:'horse',match::first)' –
[Capybara Ambiguity Resolution](http://stackoverflow.com/questions/13132506/capybara-ambiguity) -解析度) –