3

I have thead and tbody in the table. Thead contains a few s in . Each of it have an id. I need to find the index of td in thead by id and then find by index in tbody.

<table>
  <thead>
   <tr>
     <td data-date="2019-08-05"></td>
     <td data-date="2019-08-06"></td> //find index of this element
     <td data-date="2019-08-07"></td>
   </tr>
  </thead>
  <tbody>
   <tr>
    <td>aaa</td>
    <td>bbb</td> //find this element by found index
    <td>ccc</td>
   </tr>
  </tbody>
</table>
 upd
<table>
  <thead>
   <tr>
     <td data-date="2019-08-05"></td>
     <td data-date="2019-08-06"></td> 
     <td data-date="2019-08-07"></td> 
     <td data-date="2019-08-08"></td> //find index of this element
     <td data-date="2019-08-09"></td>
   </tr>
  </thead>
  <tbody>
   <tr>
    <td rowspan="2"></td>
    <td rowspan="2" class="rrrr">event1 2019-08-06</td>
    <td class="rrrr">event1 2019-08-07</td>
    <td class="rrrr"event1 2019-08-08</td> //find this element by found index
    <td rowspan="2"></td>
   </tr>
   <tr>
    <td class="rrrr">event2 2019-08-07</td>
    <td class="rrrr">event2 2019-08-08</td> //find this element by found index
   </tr>
  </tbody>
</table>

1 Answers1

3

This xpath expression

//tbody//td[count(//thead//td[@data-date='2019-08-06']/preceding-sibling::*)+1]

selects

<td>bbb</td>
Jack Fleeting
  • 24,385
  • 6
  • 23
  • 45
  • @DebanjanB - Thank you; much appreciated, especially coming from you! – Jack Fleeting Aug 30 '19 at 16:09
  • @JackFleeting, Hi again, after some upd of code, i have td. this tag can have rowspan and can not have it, but always have class "rrr". I need to find tds with same attributes(with rowspan or not) and then find by index find td in the next tr by this index. please, help – John Brewer Sep 02 '19 at 11:41
  • @JohnBrewer - I'm not sure are entirely understand your comment, but as a general SO policy, you should post a new question with the new, updated code, so more people can see it. – Jack Fleeting Sep 02 '19 at 12:59
  • @JackFleeting Ok, done, link to this question https://stackoverflow.com/questions/57757779/get-second-event-from-fullcalendar-by-xpath – John Brewer Sep 02 '19 at 13:25