-1
<div class="bli-category">
<div class="row ng-scope" ng-repeat="placementtrack by $index">
<div class="col-sm-12">
<div class="col-sm-1 bli-category-checkbox">
<input class="bli-check-box ng-valid" type="checkbox" ng-click="addPlacement" ng-checked="checkedPlacementIndex" ng-model="selectedPlacement">
</div>
<div class="col-sm-8 bli-category-content">
<div class="ng-binding" ng-bind="placement.placementName">page_details</div>
</div>
</div>
</div>

I need to select the checkbox in class='bli-check-box ng-valid' for the text in class='ng-binding' When I try to get the xpath like

//input[@class='bli-check-box ng-valid'] 

it selects all the 4-5 checkboxes

Andersson
  • 51,635
  • 17
  • 77
  • 129
prafful24
  • 57
  • 7

2 Answers2

0

To select the checkbox in class='bli-check-box ng-valid' with respect to the text in class='ng-binding' i.e. page_details you can use the following xpath :

//div[@class='bli-category']//div[@class='ng-binding' and contains(.,'page_details')]//preceding::input[@class='bli-check-box ng-valid']

Note : As the element is an Angular element you have to induce wait for the element to be clickable before attempting to click.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0
//div[text='page_detials' and class='ng-binding']/../preceding-sibling::div//input[class='bli-check-box ng-valid']

The above xpath starts with finding the node which has the custom text that you know. It then traverses to its parent and then its previous sibling which in your case houses your required input node. So after traversing to the div you select its child which is your required input node.

hiren
  • 1,067
  • 1
  • 9
  • 16