如何在 watir 中找出带有复选框的单元格?

how to find out a cell that has checkbox in it in watir?

我有一个包含多个列和行的 table,在某些单元格中有复选框。 那么我怎样才能在 watir 中闪烁这些单元格呢? 有没有方法 returns 什么元素位于特定的单元格中?

在没有看到示例 HTML 的情况下,这完全是在黑暗中拍摄的,但这是一种可能的方法。

考虑到这个人为的 HTML 片段:

<table>
  <tr><td id="foo"><input type="checkbox" name="foo"></tr></td>
  <tr><td id="bar"><input type="checkbox" name="bar"></tr></td>
  <tr><td id="text">text</tr></td>
</table>

您可以使用 checkboxes 方法定位复选框,然后使用 parent 方法获取包含该复选框的单元格的 ID(假设该单元格有一个 ID):

b.checkboxes.each { |checkbox| puts checkbox.parent.id}
#=> foo
#=> bar

如果您想 flash 复选框,这可能会起作用,具体取决于页面的实现方式:

b.checkboxes.each { |checkbox| checkbox.flash}

就像我说的,完全是猜测。但现在是捐赠季节,所以你去吧。