tags:

views:

222

answers:

1

Hi, 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.each 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.

+2  A: 

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.

Željko Filipin
don't you still have access to row from outside and could just do:row.radio(how, what).set
mandersn
@mandersn, good point, it would probably work.
Željko Filipin
Thanks for the replys. the radio set button above does not work. but using what mandersn said it works. row.radio(:name,'radioButton').set or browser.radio(:name => 'radioButton', :index=>index).set is fine
AJ