xeon48 xeon48 - 6 months ago 179
AngularJS Question

Select ng-repeat checkbox Selenium

I have my ng-repeat checkbox selection :

<label> <input style="display: inline-block; margin-top: 5px"
type="checkbox"
ng-model="entity.checked"
ng-change="getEntityFromModal(entity.val, entity.checked)" /> <span>{{entity.val}}</span>
</label>


I'm trying to locate a checkbox represented by the label
01
with this:

multiCheckBoxXPath = "//input(@ng-model='entity.checked')/label[contains(text(),'" +value.substring(0, 2) +"')]";


Where value is an elongated
string
version of what is displayed beside checkbox. First two letters are displayed.

I'm locating it via the label using a
[contains(text())
then using the assigned
ng-model
to try and select the corresponding checkbox.

Unfortunately I'm getting -

Unable to find //input(@ng-model='entity.checked')/label[contains(text(),'01')]


I'm a bit stuck here so any ideas appreciated.

Answer

try this xpath

"//span[contains(text(),'" +value.substring(0, 2) +"')]/preceding-sibling::input"

Hope it will help you..:)