title: Locate the sibling element of self or perent node in xpath
body: <p>I'm trying to find an element which can be preceding sibling of self node or its parent's node .</p>
  
  <p>I have to get all textfield values along with the label present for them as given this image :</p>
  
  <p><a href="https://i.stack.imgur.com/Q8NFp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q8NFp.png" alt="enter image description here"></a></p>
  
  <p>If I see the DOM I found following structure as mentioned in snap</p>
  
  <p><a href="https://i.stack.imgur.com/1fT2K.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1fT2K.png" alt="enter image description here"></a></p>
  
  <p>I have tried below code</p>
  
  <pre><code> // this is the xpath to get all the textboxes
  
  @FindBy(xpath = "//input[not(@id='fuPanCardFilePath')][not(@type='hidden')][not(@id='fuIDProofFilePath' or @id='txtChangePhone' or @id='txtOTP' )]")
  public List&lt;WebElement&gt; allTextFieldsDetails;
  
  
  // This how i am getting labels of correspondent textfield
  
  for(WebElement e : allTextFieldsDetails)
  {
      LogWriter.logger.info(e.findElement(By.xpath("preceding-sibling::label")).getText() +"---"+e.getAttribute("value"));
  }
  </code></pre>
  
  <p>Its working fine for those <code>&lt;label&gt;</code> which is exact preceding-sibling of <code>&lt;input&gt;</code> but if a <code>label</code> is preceding-sibling of the parent <code>div</code> of a <code>input</code> tag then its throw the exception <code>NoSuchElementException</code>.</p>
  
  <p>This is HTML structure :</p>
  
  <pre><code>&lt;div class="row"&gt;
      &lt;div class="col-sm-6 form-group"&gt;
          &lt;label&gt;Last Name &lt;/label&gt;
          &lt;input id="LastName" class="form-control valid" data-val="true" data-val-length="The field Last Name must be a string with a maximum length of 20." data-val-length-max="20" data-val-regex="Please enter valid Last Name" data-val-regex-pattern="[a-zA-Z ]+" data-val-required="Please enter valid Last Name" maxlength="20" name="LastName" placeholder="Last Name" value="Kapadia" aria-required="true" aria-describedby="LastName-error" aria-invalid="false" type="text"/&gt;
          &lt;span class="field-validation-valid" data-valmsg-for="LastName" data-valmsg-replace="true"/&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="row"&gt;
      &lt;div class="col-sm-6 form-group"&gt;
          &lt;label&gt;Email ID&lt;/label&gt;
          &lt;input id="Email" class="form-control valid" data-val="true" data-val-length="The field Email must be a string with a maximum length of 320." data-val-length-max="320" data-val-regex="Please enter valid Email" data-val-regex-pattern="[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,3}$" data-val-required="Please enter valid Email" maxlength="80" name="Email" placeholder="Email" value="narendra.h.rajput@trimantra.net" aria-required="true" aria-describedby="Email-error" aria-invalid="false" type="email"/&gt;
          &lt;span class="field-validation-valid" data-valmsg-for="Email" data-valmsg-replace="true"/&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="col-sm-6 form-group"&gt;
          &lt;label&gt;Date Of Birth&lt;/label&gt;
          &lt;div class="input-append date tspDOB-date"&gt;
              &lt;input id="DOB" class="form-control" value="1989-09-09" data-val="true" data-val-date="The field Date of Birth must be a date." data-val-required="Please enter a valid birth date" name="DOB" placeholder="Date of Birth" type="text"/&gt;
              &lt;span class="field-validation-valid" data-valmsg-for="DOB" data-valmsg-replace="true"/&gt;
              &lt;span class="add-on"/&gt;
          &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="row"&gt;
      &lt;div class="col-sm-6 form-group"&gt;
          &lt;label&gt;Mobile No&lt;/label&gt;
          &lt;div class="col-sm-12 form-group displayinlinediv"&gt;
              &lt;input id="Mobile" class="form-control valid" name="Mobile" readonly="readonly" value="00000000000" aria-invalid="false" type="text"/&gt;
              &lt;button id="btnchange" class="btn btn-common-left" type="button"&gt;Change&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I want to locate the labels correspondent to input fields. </p>