通过 XPath 获取 tr 中特定 td 的索引

Get index of the specific td in tr by XPath

我在 table 中有 thead 和 tbody。 Thead 中包含几个 s。每个都有一个ID。我需要通过id在thead中找到td的索引,然后在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>

这个 xpath 表达式

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

选择

<td>bbb</td>