1

次の html を検討して ください http://www.carbide-red.com/prog/test_table.html

を使用して、列を左から右に移動できることがわかりました

browser.td(:text => "Equipment").parent.td(:index => "2").flash

「Equipement」を含む行の 3 番目の列をフラッシュします。

しかし、どうすれば特定の数の行を下に移動できますか? 私は .tr と .rows を使用して運が悪いのですが、どのように試しても、それらを使用するとクラッシュします。といった単純なものでも

browser.tr(:text => "Equipment").flash

tr/row の仕組みを誤解しているだけですか?

4

1 に答える 1

4

特定の行/列

必要な行/列を既に計算しているようです。次のようにするだけで、特定の行/列インデックスのセルを取得できます。

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

それが役立つかどうか、または具体的な例があれば教えてください。

于 2012-09-11T15:10:14.370 に答える