用于字段比较的 watir-webdriver 迭代表
如何迭代该表的行并比较每个第一列的值, 即'钱包1'=='钱包2'?
当字段值相同时,比较第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
How can I iterate this table's rows and compare the value of each first column,
i.e 'Wallet1' == 'Wallet2' ?
And when the field has the same value, compare the 4th column value?
<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>
My first approach used variations of,
$browser.table(:class, 'simple').rows[1..-1].each do |row|
but I'm facing a roadblock.
Also, why does not this work?
$browser.tr(:class => /odd|even/) do |row|
puts row(:index => 0).text
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过首先对集合进行排序或其他操作,或者将所有值提取到数组中并使用一些数组函数来查找匹配的行,这可能会更快。我确信有空间使
第一行的开头更加优雅,与下面的每一行相比,
移动到下一行,重复
This could probably be made faster by sorting the collection first or something, or maybe extracting all the values into arrays and using some array functions to find the matching rows. I'm sure there is room to make this more elegant
start with the first row, compare to every row below it,
move to next row, repeat