如何循环遍历具有相同类名的不同文本字段

时间:2014-09-29 17:53:16

标签: ruby watir-webdriver

我的HTML

<div class='participants'>

        <div class="participant_period" data-view="scorecards&#x2F;participant_edit" data-model_id="348292" data-model_name="scorecard_participants" data-view-data.model="{&quot;type&quot;:&quot;model&quot;,&quot;key&quot;:&quot;model:scorecard_participants:348292&quot;,&quot;model&quot;:&quot;scorecard_participants&quot;,&quot;id&quot;:&quot;348292&quot;}" 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&#x2F;participant_edit" data-model_id="347821" data-model_name="scorecard_participants" data-view-data.model="{&quot;type&quot;:&quot;model&quot;,&quot;key&quot;:&quot;model:scorecard_participants:347821&quot;,&quot;model&quot;:&quot;scorecard_participants&quot;,&quot;id&quot;:&quot;347821&quot;}" 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>
  • 我想填补tex字段&#34;输入名称= final_score&#34;随机数据与循环 任何人都可以建议我怎么做呢

我的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) }

1 个答案:

答案 0 :(得分:0)

尝试类似:

@browser.inputs(:name => 'final_score').each do |field|
  field.send_keys data
end