开发者

Watir question regarding table rows and loop

开发者 https://www.devze.com 2022-12-31 20:26 出处:网络
I would like to go through a table and look for a word, if that word appears, i would like to click on a radio button in the same row, but not the same column, then stop the loop.

I would like to go through a table and look for a word, if that word appears, i would like to click on a radio button in the same row, but not the same column, then stop the loop. I have something like this at the moment but i dont know where to go on from here.

  @ie.div(:class, 'tableclass').table(:index, 1).each do | row |
     row.ea开发者_如何学JAVAch do | cell |
    if (cell.text() == 'text')
      ##Set radio button
break end end end

I tried selecting a radio by name and index, but i do not know how to get the row number that it is currently at. Thanks.


each_with_index is what you need. Something like this should work (not tested):

browser.div(:class, 'tableclass').table(:index, 1).rows.each_with_index do |row, index|
  row.cells.each do |cell|
    if cell.text == 'text'
      browser.div(:class, 'tableclass').table(:index, 1)[index].radio(how, what).set
      break
    end
  end
end

I could test it if you post relevant HTML snippet.

0

精彩评论

暂无评论...
验证码 换一张
取 消