Marj
Marj

Reputation: 312

How do I obtain count of rows under the visible rows(non Angular) using protractor?

I have the following HTML:

<tr id="resultsRepeaterGrid">
 <tr id="tableheader"></tr>
  <tr id="Data list1_datarow">
    <div style>row 1</div>
    <tr id = "expanded row"></tr>
  </tr>
  <tr id="Data list2_datarow">
    <div style>row 2</div>
    <tr id = "expanded row"></tr>
  </tr>
  <tr id="Data list3_datarow">
    <div style>row 1</div>
    <tr id = "expanded row"></tr>
  </tr>
</tr>

What I would like to do is get the count of all the <tr> that are children of the <tr> with the id of 'resultsRepeaterGrid'. You'll find below the protractor code:

var searchResCount = element.all(by.id('resultsRepeaterGrid'))
expect(searchResCount.count()).toEqual(3);

But I am getting an error of

Expected 1 to equal 3.

I would like to discard the and part because I only intend to count the result rows which is under the datalist_datarow. Thanks

Upvotes: 1

Views: 869

Answers (2)

Belfordz
Belfordz

Reputation: 630

Here is a selector based on the dom structure above.

var searchResCount = element.all(by.css('#resultsRepeaterGrid > tr:not(.tableheader)'))
expect(searchResCount.count()).toEqual(3);

However, it is quite possible that you have a timing issue. You can try something like this:

  browser.wait(function() {
    return element(by.css('#Data')).isDisplayed();
  }, 10000);

Upvotes: 1

DiegoSalazar
DiegoSalazar

Reputation: 13521

Your query has to select the rows, right now you're selecting just the table element so it's count is 1.

change your selector to include the tr elements:

element.all(by.css('#resultsRepeaterGrid > tr'))

Upvotes: 0

Related Questions