M M
M M

Reputation: 99

How to validate content of particular row based on value of one of the column in protractor?

I want to validate row of table for some specific column value. For example table HTML as below , here i want validate entire row where pn is Plan WL. Please suggest locator with either classname or css as we are no using Xpath.

<ng-component>
<div class="card">
<div class="table 0">
<table class="table 1">
<thead class="fi-header">
<tr>
<th>PG</th>
<th>N/U</th>
<th>RB</th>
<th>PC</th>
<th>PN</th>
<th>CT</th>
<th>T</th>
<th>D</th>
<th>S</th>
<th>C</th>
<th>Ca</th>
<th>OG</th>
<th>D</th>
</tr>
</thead>
<tbody>
<tr class="conf-0">
<td class="pg">Group 1</td>
<td>
<span class="is-n">New</span>
</td>
<td class="rb">123</td>
<td class="pc">AB</td>
<td class="pn">Alpha Bravo</td>
<td class="ct">Type 1</td>
<td class="t">6</td>
<td class="d">15000</td>
<td class="s">MR</td>
<td class="c">Sedan</td>
<td class="ca">Allstate</td>
<td class="og">Grp. 1</td>
<td> </td>
</tr>
<tr class="conf-1">
<td class="pg">Group 1</td>
<td>
<span class="is-n">Used</span>
</td>
<td class="rb">123</td>
<td class="pc">WL</td>
<td class="pn">Plan WL</td>
<td class="ct">Type 2</td>
<td class="t">6</td>
<td class="d">15000</td>
<td class="s">MR</td>
<td class="c">SUV</td>
<td class="ca">Allstate</td>
<td class="og">Grp. 1</td>
<td>
<span class="dr-0">
<a class="dr" href="javascript:void(0)">
<span>
<span class="dr-start-date">3/22/2017</span>
-
<span class="dr-end-date">3/22/2017</span>
,
</span>
</a>
</span>
<span class="dr-1">
<a class="dr" href="javascript:void(0)">
<span>
<span class="dr-start-date">3/22/2017</span>
-
<span class="dr-end-date">3/22/2017</span>
,
</span>
</a>
</span>
<span class="dr-2">
<a class="dr" href="javascript:void(0)">
<span>
<span class="dr-start-date">3/22/2017</span>
-
<span class="dr-end-date">3/22/2017</span>
</span>
</a>
</span>
</td>
</tr>

</tbody>
</table>
</div>
</div>
</ng-component>

Upvotes: 1

Views: 138

Answers (1)

AdityaReddy
AdityaReddy

Reputation: 3645

Something as simple as this - element(by.cssContainingText('tr', 'Plan WL')) will fetch your the row that contains text - Plan WL anywhere horizontally.

In case your requirement is to accurately check if the expected text is occurring at a specific column value you can do this.

var requiredRow = element.all(by.css('tr')).filter(function(elem, index) {
    return elem.element(by.css('.pn')).getText().then(function(text) {
        return text === 'Plan WL';
    });
}).first();

Upvotes: 1

Related Questions