I am creating a function called GetTextboxLabel which does exactly what it says, gets the label of the given IWebElement declared in my POM framework.
Instead of declaring every textbox label in the page object classes, I would rather just be able to call something like the following:
Textbox.GetTextboxLabel()
And then use that in assertions, like this:
Assert.That("Username:" == Username.GetTextboxLabel());
In my application each label field is directly above the textbox field, so it is safe to assume that the first html element with the type of label above the textbox (input) html element in the DOM is the textboxes label. You can see here that I have an input with "id='CUSIP'" and above it, there is a label with the text of 'CUSIP'. The function would return the label text.
<div class="form-group">
<label class="control-label col-md-3">CUSIP</label>
<div class="col-md-9">
<input class="form-control" data-val="true" data-val-length="CUSIP must be exactly 9 characters long" data-val-length-max="9" data-val-length-min="9" data-val-required="The Cusip field is required." id="Cusip" name="Cusip" type="text" value="">
<span class="field-validation-valid" data-valmsg-for="Cusip" data-valmsg-replace="true"></span>
</div>
</div>
Could anyone offer some assistance? Is there any way to do this with XPath? Any advice would be appreciated.
EDIT: I am seeking the PREVIOUS label field, not the next.