Robert Harvey
Robert Harvey

Reputation: 180808

XPath to return the next column following the td containing a specific text string?

I have the following HTML (a small part of a larger HTML document):

<tr class="even">
  <td width="35%"><strong>Restrictions or particulars</strong></td>
  <td>
    MAINTENANCE OF REFRIGERATION/AIR CONDITIONING UP TO 1000v - REFRIGERATION/AIRCON EQPT<br>
  </td>
</tr>

What would be the XPath expression that identifies the string Restrictions or particulars, and then returns the text in the immediately following td (MAINTENANCE OF REFRIGERATION/AIR CONDITIONING UP TO 1000v - REFRIGERATION/AIRCON EQPT)?

Upvotes: 0

Views: 440

Answers (2)

Jeff Mercado
Jeff Mercado

Reputation: 134891

There's a number of ways you could do this. I would select the surrounding tr node that has the associated td with that name, then take the second td.

//tr[td[1]='Restrictions or particulars']/td[2]

Upvotes: 1

Robert Harvey
Robert Harvey

Reputation: 180808

//tr[contains(td, 'Restrictions or particulars')]/td[2]/text()

Upvotes: 0

Related Questions