Home > Net >  Xpath: How to identify a row in a table via its elements in the columns?
Xpath: How to identify a row in a table via its elements in the columns?

Time:09-22

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>

CodePudding user response:

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'))])]
  • Related