Here is my sample source HTML:
<!-- Many other elements above this -->
<div class="emf-div-field">
<span style="width:175px">
<input class="validate[required]" style="width:100%" value="" id="element_2" name="element_2" type="text">
<label for="element_2" class="emf-bottom-label emf-text-center">First</label>
</span>
<span style="width:125px">
<input class="validate[optional]" style="width:100%" value="" id="element_6" name="element_6" type="text">
<label for="element_6" class="emf-bottom-label emf-text-center">Middle</label>
</span>
<span style="width:175px">
<input class="validate[required]" style="width:100%" value="" id="element_3" name="element_3" type="text">
<label for="element_3" class="emf-bottom-label emf-text-center">Last</label>
</span>
</div>
<!-- Many other elements below this -->
I need the XPath to select the <input> element just prior to the <label> element whose innerText is "First". The <input> element is always a sibling of the <label> element.
It needs to be a relative selection, based on the <label> innerText because in general these statements could be at many different levels.
I have tried this (and many other variations), but none have worked:
//input[preceding-sibling::label[text() = "First"]]
Thanks.
<label>tag? Can you make it:<label for="element_2" class="emf-bottom-label emf-text-center" text="First">First</label>and use the css selectordiv span input+label[text="First"] { color: red; }?