I am currently in process of creating a framework using Protractor. I was trying to use cssContainingText
locator given by the Protractor API. However, the locator failed giving an invalidElement
exception, which seemed wierd to me.
The HTML of the page looks like this
<tbody>
<tr class="row2">
<td class="action-checkbox">...</td>
<th class="field-name">
<a href="some_link">someText</a>
</th>
<td class="field-slug">sometext</td>
</tr>
<tr class="row3">
<td class="action-checkbox">...</td>
<th class="field-name">
<a href="some_link">someOtherText</a>
</th>
<td class="field-slug">someothertext</td>
</tr>
<tr class="row4">...</tr>
<td class="action-checkbox">...</td>
<th class="field-name">
<a href="some_link">someThirdText</a>
</th>
<td class="field-slug">somethirdtext</td>
</tr>
I was trying to use the text someText
using the following locator-
element(by.cssContainingText('.field-name','someText'));
, which weirdly gives an InvalidLocator
exception. When I use the following locator element(by.cssContainingText('a','someText'))
, the code works perfectly fine.
As per what I understand from the explanation given here, and the Protractor implementation given here, the cssContainingText
first locates all the elements using the CSS Selector and then matches the required text.
So, it seems perfectly fine to me to use the .field-name
class name for the CSS Selector and then match the desired string. However, this fails, which I am not able to understand. Inputs on this would be helpful.