Cucumber 有可能在水豚中选择多个相等的元素吗?

Cucumber 有可能在水豚中选择多个相等的元素吗?,cucumber,capybara,Cucumber,Capybara,我开始研究以下gems的自动测试capybara,cucumber,SitePrism,webdriver,我在测试中看到的一件事是输入类型字段如果重复的话 有些人喜欢这样: <input type="text" placeholder="some cool text"/> <input type="text" placeholder="some cool text"/> <input

我开始研究以下gems的自动测试
capybara
cucumber
SitePrism
webdriver
,我在测试中看到的一件事是输入类型字段如果重复的话

有些人喜欢这样:

<input type="text" placeholder="some cool text"/>
<input type="text" placeholder="some cool text"/>
<input type="text" placeholder="some cool text"/>

我很难找到答案,一次定义一个循环不会有问题,但我不知道如何同时选择它们。

find
仅限于返回一个元素,如果需要多个元素,则需要使用
all
。用水豚之类的

page.all('input', text: 'some cool text').each do |inp| 
  inp.set('A simple string')
end
我会照你说的做。如果要确保处理的元素正好是3个匹配元素,可以使用
计数
选项(还有
最小值
最大值
,以及
之间的可用选项)

更新:因为你已经更新了你可以做的问题

page.all("input[placeholder='some cool text']", count: 3).each do |inp| 
  inp.set('A simple string')
end
但我可能会使用水豚提供的选择器类型,如

page.all(:fillable_field, placeholder: 'some cool text', count: 3).each do |inp|
  inp.set('A simple string')
end

你帮了我很多,我不知道这个概念,但是为了评估编辑答案的正确性,因为我的一次事故,它通常是
('input',text:'some cool text')
,它是接收
(“[placeholder='some cool text'])
,我也将编辑我的问题。@WEBLastWolf根据您对问题的更改向答案添加了更新信息
page.all("input[placeholder='some cool text']", count: 3).each do |inp| 
  inp.set('A simple string')
end
page.all(:fillable_field, placeholder: 'some cool text', count: 3).each do |inp|
  inp.set('A simple string')
end