特定の行/列
必要な行/列を既に計算しているようです。次のようにするだけで、特定の行/列インデックスのセルを取得できます。
browser.table[row_index][column_index]
row_index
とは、必要な行column_index
と列の整数です (ゼロベースのインデックスであることに注意してください)。
特定の行
次のようにして、インデックスに基づいて行を選択することもできます。
browser.table.tr(:index, 1).flash
browser.table.row(:index, 2).flash
ネストされたテーブルを無視する一方で.tr
、ネストされたテーブルを含むことに注意してください。.row
更新 - 特定の行の後の行を検索
特定のテキストを含む特定の行の次の行を検索するには、まず特定の行のインデックスを決定します。次に、それに関連する他の行を見つけることができます。ここではいくつかの例を示します。
#Get the 3rd row down from the row containing the text 'Equipment'
starting_row_index = browser.table.rows.to_a.index{ |row| row.text =~ /Equipment/ }
offset = 3
row = browser.table.row(:index, starting_row_index + offset)
puts row.text
# => CAT03 ...
#Get the 3rd row down from the row containing a cell with yellow background colour
starting_row_index = browser.table.rows.to_a.index{ |row| row.td(:css => "td[bgcolor=yellow]").present? }
offset = 3
row = browser.table.row(:index, starting_row_index + offset)
puts row.text
# => ETS36401 ...
#Output the first column text of each row after the row containing a cell with yellow background colour
starting_row_index = browser.table.rows.to_a.index{ |row| row.td(:css => "td[bgcolor=yellow]").present? }
(starting_row_index + 1).upto(browser.table.rows.length - 1){ |x| puts browser.table[x][0].text }
# => CAT03, CAT08, ..., INTEGRA10, INTEGRA11
それが役立つかどうか、または具体的な例があれば教えてください。