xeon48 xeon48 - 1 year ago 362
AngularJS Question

Select ng-repeat checkbox Selenium

I have my ng-repeat checkbox selection :

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

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

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

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

I'm locating it via the label using a
then using the assigned
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 Source

try this xpath

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

Hope it will help you..:)