Find an item that does not have a style

advertisements

In a table, there are rows like this:

<tr id="filtersJob_intrinsicTable_row6" class="evenRow" style="display: none;">some stuff here<tr>
<tr id="filtersJob_intrinsicTable_row7" class="evenRow">some stuff here<tr>

How do i use watir to get the rows which are to be displayed, i.e the rows which do NOT have style="display: none; ?


You have a number of ways of collecting elements without the style attribute:

Using a :css locator:

browser.trs(css: 'tr:not([style])')

Using a :xpath locator:

browser.trs(xpath: '//tr[not(@style)]')

You could also check the attribute value:

browser.trs.select { |tr| tr.attribute_value('style').nil? }

Note that you should be cautious about using the style attribute as an indicator of the row being displayed. Someone could add some other unrelated style property and then all of the tests will fail. Instead, I would suggest that you look for rows that are present:

browser.trs.select(&:present?)

I think that this also makes the purpose of the code more obvious and readable.