Currently working on a framework utilizing Protractor, I encountered an issue with the cssContainingText
locator from the Protractor API. The locator threw an invalidElement
exception, which puzzled me.
The structure of the HTML page appears as follows:
<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>
My attempt to use the text someText
with the following locator failed:
element(by.cssContainingText('.field-name','someText'));
, throwing an InvalidLocator
exception. However, using element(by.cssContainingText('a','someText'))
works perfectly fine.
After reviewing explanations in this source and examining the Protractor implementation detailed here, it appears that cssContainingText
first locates elements using the CSS Selector and then matches the desired text.
It should be correct to use the .field-name
class name for the CSS Selector and match the desired string, but this approach fails inexplicably. Any insights on this matter would be appreciated.