Watir How to get rows with different classes

空扰寡人 提交于 2019-12-13 06:05:20

问题


I need to get all rows with class named 'odd_row' or 'even_row'.

HTML:

<tbody>
    <tr class="first_row"> … </tr>
    <tr class="subjectField" style="display:none"> … </tr>
    <tr class="odd_row"> … </tr>
    <tr class="subjectField" style="display:none"> … </tr>
    <tr class="even_row"> … </tr>
    <tr class="subjectField" style="display:none"> … </tr>
</tbody>

I tried this:

@b.table(:class => 'color_table').tbody.trs(:class => ('odd_row' || 'even_row').size

But it returns 1.

Does anybody know how to solve this problem?


回答1:


If you want to do an "or" of classes, you need to use a regular expression. In regular expressions, "or" is done using a single pipe character "|". The class locator you would want is:

:class => /odd_row|even_row/

Therefore, to count all odd and even rows, you want:

@b.table(:class => 'color_table')
  .tbody
  .trs(:class => /odd_row|even_row/)
  .size



回答2:


You are calling .size at the end. This gets the size of the array as an integer. You can try without it.



来源:https://stackoverflow.com/questions/20610984/watir-how-to-get-rows-with-different-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!