Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Locate a td with a specific value using xpath

Tags:

xpath

Consider the following html fragment:

<table>
  <tr>
    <td>One</td><td>1</td>
    <td>Two</td><td>2</td>
  </tr>
</table>

I want to use xpath to find the second td ("1" or "2") based on the value of the first td ("One" or "Two). Something like:

/table/tr/td[text() = 'One']/../td

or

/table/tr/td[text(), 'One']/../td

Any ideas?

like image 419
Todd R Avatar asked Feb 12 '10 20:02

Todd R


2 Answers

/table/tr/td[text()='One']/following-sibling::td[1]

"The first td following-sibling of a td node with text One"

like image 82
AakashM Avatar answered Sep 20 '22 05:09

AakashM


following-sibling::td?

like image 33
brian Avatar answered Sep 19 '22 05:09

brian