如何迭代此表的行并比较每个第一列的值, 即'Wallet1'=='Wallet2'?
当字段具有相同的值时,比较第4列值?
<table class="simple">
<tbody><tr>
<th class="labelCenter">Saldo</th>
(...)
</tr>
<tr class="odd">
<td class="labelCenter">Wallet 1</td>
<td class="labelCenter">Decresing</td>
<td class="labelCenter">16/02/2012 19:06:01</td>
<td class="labelCenter">19/02/2012 14:03:01</td>
<td class="labelCenter">
</td>
<td class="labelRight">
78,90
</td>
<td class="labelRight">
0,00
</td>
<td class="labelCenter">Value</td>
</tr>
<tr class="even">
<td class="labelCenter">Wallet 2</td>
<td class="labelCenter">Increasing</td>
<td class="labelCenter">16/02/2012 19:06:01</td>
<td class="labelCenter">19/02/2012 11:09:01</td>
<td class="labelCenter">
</td>
<td class="labelRight">
0,00
</td>
<td class="labelRight">
0,00
</td>
<td class="labelCenter">Value</td>
</tr>
</tbody></table>
我的第一种方法使用了
的变体$browser.table(:class, 'simple').rows[1..-1].each do |row|
但我正面临着障碍。
另外,为什么这不起作用?
$browser.tr(:class => /odd|even/) do |row|
puts row(:index => 0).text
答案 0 :(得分:2)
通过首先对集合进行排序,或者将所有值提取到数组中并使用一些数组函数来查找匹配的行,可以更快地实现这一点。我确信还有空间让这更优雅
从第一行开始,与下面的每一行进行比较, 转到下一行,重复
rows = $browser.table(:class, 'simple').rows
last = rows.length -1
last.times do |current|
remaining = last - current
remaining.times do |j|
if rows[current].cell.text == rows[j+1].cell.text
if rows[current].cell(:index => 3).text == rows[j+1].cell(:index => 3).text
#do something
end
end
end
end
答案 1 :(得分:1)
$browser.table.trs(:class => /odd|even/).each do |tr|
puts tr.td(:index => 0).text
end