0
<table class="">
 <tbody class>
   <tr class>
   <tr class>
   <tr class>
     <td>
      <span>Series</span>
     <td>CAT5</td>

The number of tr and td can be different because there are multiples tables and I needed it in a xpath format like this:

//table[@class="info-table specifications-table"]/tbody/tr/td/span[contains(text(),'Series')]/....

I tried like this but the tr order is different each time, the only constant is the value is always on the Series row in the table

//table[@class="info-table specifications-table"]/tbody/tr[8]/td[2]

Table looks like this and the Series can be on different position from top to bottom

  • 1
    What did you try? And what didn't work? – cloned Jul 19 '21 at 11:48
  • This what I tried but is not working because the td is not a sibling of the span `//table[@class="info-table specifications-table"]/tbody/tr/td/span[contains(text(),'Series')]/following-sibling::td` – Roman Marius Jul 19 '21 at 12:26
  • add a [parent selector then?](https://stackoverflow.com/questions/28237694/xpath-get-parent-node-from-child-node) Maybe something like `//table[@class="info-table specifications-table"]/tbody/tr/td/span[contains(text(),'Series')]/parent::td/following-sibling::td` – cloned Jul 19 '21 at 13:14

1 Answers1

0

You can either use textContent (or innerHTML) to get the desired result:

The xpath for solving this is using parent selector like described here:

//table[@class="info-table specifications-table"]/tbody/tr/td/span[contains(text(),'Series')]/parent::td/following-sibling::td

document.querySelectorAll('tr td:nth-child(2)').forEach(td => console.log(td.textContent))
<table class="">
  <tbody class>
    <tr class>
      <td>
        <span>Series</span>
      </td>
      <td>CAT5</td>
    </tr>
    <tr class>
      <td>
        <span>Series</span>
      </td>
      <td>CAT1</td>
    </tr>
  </tbody>
</table>
cloned
  • 6,346
  • 4
  • 26
  • 38
  • I need the xpath so something like this: //table[@class="info-table specifications-table"]/tbody/tr/td/span[contains(text(),'Series')]/.... – Roman Marius Jul 19 '21 at 11:53
  • That's a totally different thing than what you posted in your question. Please update your question with all info that we need. – cloned Jul 19 '21 at 11:58