On Thursday, June 14, 2012 12:41:31 PM UTC-7, Joshua Homer wrote:
>
> Here is what I am trying to do:
>
> 1) go through each row in table
> 2) go through each cell in rows
> 3) look for "905" in each cell
> 4) when "905" is found click on the button with the title "Edit User" in
> the row
>
> Here is the code I have:
>
> def test_setupUser
>>
>> @loginPage.login("joshh", "test")
>>
>> @browser.link(:href, "/admin/admin").click
>>
>> @browser.table.rows.each do |row|
>>
>> row.cells.each do |cell|
>>
>> if cell.text.include? "905"
>>
>> row.button(:title, "Edit User").click
>>
>> end
>>
>> end
>>
>> end
>>
>> end
>>
>>
> Thank you for your help.
>
So the way you have this, it could potentially click Edit User multiple
times, is that what you want?
If you just want to find the first row that has a cell that has "905" in
its text, then this ought to do what you want
browser.cell(:text => /905/).parent.button(:title, "Edit User").click
Otherwise why not select just the rows you want and iterate the list, that
saves on a lot of testing and sub-iteration of the cells on each row
browser.table.rows(:text => /905/) do |row|
row.button(:title, "Edit User").click
end
The danger with the one above would be that if you have two cells that
somehow combine to form "905" (from end text in one cell and starting text
in another) then you might end up selecting unintended rows, since I can't
see your HTML I have no idea if that would be an issue for you or not.
--
Before posting, please read http://watir.com/support. In short: search before
you ask, be nice.
[email protected]
http://groups.google.com/group/watir-general
[email protected]