Todd R
Todd R

Reputation: 18516

Locate a td with a specific value using 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?

Upvotes: 8

Views: 24530

Answers (2)

AakashM
AakashM

Reputation: 63338

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

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

Upvotes: 21

brian
brian

Reputation: 1080

following-sibling::td?

Upvotes: 1

Related Questions