我的HTML
<div class='participants'>
<div class="participant_period" data-view="scorecards/participant_edit" data-model_id="348292" data-model_name="scorecard_participants" data-view-data.model="{"type":"model","key":"model:scorecard_participants:348292","model":"scorecard_participants","id":"348292"}" data-model-name="scorecard_participants" data-model-id="348292"><div class="content-item content-full content-results content-box-score">
<span class="profile-image"><img src="//d3f4b3d8pglafo.cloudfront.net/system/teams/images/348292/thumb/profile" /></span>
<span class="profile-name"><a href="/teams/web-driver-baseball-team1-348292">Web-driver Baseball Team1</a></span>
<div class='row'>
<div class='col col-control'>
<div class='final-header'>Score</div>
<div class='period-score'>
<input name=final_score type="text" size="5" placeholder="-" value="" />
</div>
</div>
</div>
</div>
</div>
<div class="participant_period" data-view="scorecards/participant_edit" data-model_id="347821" data-model_name="scorecard_participants" data-view-data.model="{"type":"model","key":"model:scorecard_participants:347821","model":"scorecard_participants","id":"347821"}" data-model-name="scorecard_participants" data-model-id="347821"><div class="content-item content-full content-results content-box-score">
<span class="profile-image"><img src="//d3f4b3d8pglafo.cloudfront.net/system/teams/images/347821/thumb/102px-RedSoxPrimary_HangingSocks.svg.png" /></span>
<span class="profile-name"><a href="/teams/boston-red-sox-347821">Boston Red Sox</a></span>
<div class='row'>
<div class='col col-control'>
<div class='final-header'>Score</div>
<div class='period-score'>
<input name=final_score type="text" size="5" placeholder="-" value="" />
</div>
</div>
</div>
</div>
</div>
我的Watir代码如下所示
def edit_score_fields field = @ browser.text_field(:name =&gt;&#39; final_score&#39;) data = rand(1 ... 2)
s = @browser.text_fields(:class => "period-score").size
0.upto(s) { |i| @browser.text_field(:name => 'final_score', :index => '#{i}'.to_i).set(data) }
端
答案 0 :(得分:0)
尝试类似:
@browser.inputs(:name => 'final_score').each do |field|
field.send_keys data
end