1

I want to select a specific row from a table.

How can I construct an Xpath that selects the row based on the values of the column elements?

(For example: Select row where data1 = value1, data2 = value2, data3 = value3)?

<tbody>
   <tr>
      <td column1='data1'> value1 </td>
      <td column2='data2'> value2 </td>
      <td column3='data3'> value3 </td>
   </tr>
   <tr>
      <td column1='data1'> value1 </td>
      <td column2='data2'> value4 </td>
      <td column3='data3'> value5 </td>
   </tr>
</tbody>
Dev97M
  • 45
  • 5
  • Your question is basically a duplicate to https://stackoverflow.com/questions/1982624/using-xpath-how-do-i-select-a-node-based-on-its-text-content-and-value-of-an-at – kraeftbraeu Sep 22 '21 at 13:36
  • By row you mean `tr` correct? But still it is not `data1 = value1` there, but `column1='data1'` and `text = value1`. Am I right? – Prophet Sep 22 '21 at 13:36

1 Answers1

1

This should work:

//tr[./td[@column1='data1' and(contains(text(),'value1'))] and (./td[@column2='data2' and(contains(text(),'value2'))]) and (./td[@column3='data3' and(contains(text(),'value3'))])]
Prophet
  • 32,350
  • 22
  • 54
  • 79