Reputation: 637
I have roughly the following html:
<div class="form-group row">
<label class="control-label col-md-2 font-weight-bold text-right" for="Name">Name</label>
<div class="col-md-10">
<input class="form-control text-box single-line valid" data-val="true" id="Name" name="Name" type="text" value="Mark"
<span class="text-danger field-validation-valid"</span>
</div>
</div>
<div class="form-group row">
<label class="control-label col-md-2 font-weight-bold text-right" for="Address">Address</label>
<div class="col-md-10">
<input class="form-control text-box single-line valid" data-val="true" id="Address" name="Address" type="text" value="101 Windmere"
<span class="text-danger field-validation-valid"</span>
</div>
</div>
<div class="form-group row">
<label class="control-label col-md-2 font-weight-bold text-right" for="Notes">Notes</label>
<div class="col-md-10">
<input class="form-control text-box single-line valid" data-val="true" id="Notes" name="Notes" type="text" value="Sample note goes here"
<span class="text-danger field-validation-valid"</span>
</div>
</div>
<div class="form-group row">
<label class="control-label col-md-2 font-weight-bold text-right" for="Award">Award</label>
<div class="col-md-10">
<input class="form-control text-box single-line valid" data-val="true" id="Award" name="Award" type="text" value="20"
<span class="text-danger field-validation-valid"</span>
</div>
</div>
As you may be able to tell, I am dealing with a form table of sorts. I am trying to iterate over this and grab all the values. I need all the instances of "col-md-10" except the last one (Award). So I am using the following xpath:
//div[@class = 'col-md-10'][position()<4]
However, it keeps finding all four instances and doesn't stop at 3. No matter what number I put in for position. Even if I do [position()<1], it finds all four.
Any ideas?
Upvotes: 1
Views: 62
Reputation: 24940
The <span>
tags in your html aren't closed properly (they should be <span/>
). That aside, the following expression should get you there:
(//div[@class = 'col-md-10'])[position()<4]
Upvotes: 1