title: How to select single specific element between two elements using xpath
body: <p><a href="https://i.stack.imgur.com/D7R70.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D7R70.png" alt="enter image description here"></a></p>
  
  <p>I want to select Element button [...] which is between <strong>Consulting Services</strong> and <strong>Supervisory Organization</strong>. I tried many xpath with preceding and following but it always select element <strong>Supervisory Organization</strong></p>
  
  <p>Latest Xpath I tried : </p>
  
  <pre><code>(//div[text()='Consulting Services']/following::div[text()='Supervisory Organization'])[1][//preceding::ul//img[@title='Related Actions and Preview']]
  </code></pre>
  
  <p><strong>Html :</strong></p>
  
  <pre><code>&lt;div class="WPJF"&gt;
      &lt;div class="WDVV WAUV WJ3 WEWV WCWV WDKF WAKF" data-automation-id="compositeHeader" id="56$284553"&gt;
          &lt;div class="WIVV"&gt;
              &lt;ul tabindex="-2" class="WIEP WHVV" role="presentation" data-automation-id="selectedItemList"&gt;
                  &lt;li class="WMEP" role="presentation"&gt;
                      &lt;div class="WCEP WLEP" tabindex="-2" id="fac7048965494633a57cb15651618375" data-automation-id="menuItem" aria-label="Consulting Services, press delete to clear value." role="presentation" aria-posinset="1" aria-setsize="1"&gt;
                          &lt;div class="WDEP"&gt;
                              &lt;div class="WMJN WKIN WCJN" data-automation-id="selectedItem_2500$199"&gt;
                                  &lt;ul class="WAJN"&gt;&lt;/ul&gt;
                                  &lt;div class="gwt-Label WNJN WKIN" data-automation-id="promptOption" id="promptOption-gwt-uid-443" data-automation-label="Consulting Services" title="Consulting Services" aria-label="Consulting Services" role="link" tabindex="0"&gt;Consulting Services&lt;/div&gt;
                                  &lt;ul class="WAJN WFJN" role="presentation"&gt;
                                      &lt;li class="WLJN"&gt;&lt;img class="gwt-Image WLQO WFVP WPWP WBJN" src="https://impl.workday.com/wday/uiclient/static/gwt-desktop/update/WorkdayApp/8CB9E57BEDDE62E4F67DEB6E19F5308C.cache.png" draggable="false" data-automation-id="RELATED_TASK_charm" alt="" aria-label="Related Actions and Preview" title="Related Actions and Preview" aria-labelledby="promptOption-gwt-uid-443"&gt;&lt;/li&gt;
                                  &lt;/ul&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/li&gt;
              &lt;/ul&gt;
          &lt;/div&gt;
          &lt;div data-automation-id="wd-MoreLink" data-automation-morelinkexpanded="false" role="button" id="968c25d5792a4c2eaf6ca6028f1e8fdf" class="WK3P WJ3P" tabindex="0" aria-labelledby="" aria-hidden="true" style="display: none;"&gt;&lt;img class="gwt-Image WLQO WN3P" src="https://impl.workday.com/wday/uiclient/static/gwt-desktop/update/WorkdayApp/8CB9E57BEDDE62E4F67DEB6E19F5308C.cache.png" draggable="false" alt=""&gt;&lt;span class="WO3P" data-automation-id="moreLinkLabel" title="" aria-label="More (-4)"&gt;&lt;/span&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div aria-readonly="true" class="wd-Text WAUY WMUY WJ3 WIKF WAKF" data-automation-id="compositeSubHeaderTwo" id="56$284555" dir="ltr"&gt;Supervisory Organization&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>