Locate a td with a specific value using xpath

22,658

Solution 1

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

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

Solution 2

following-sibling::td?

Share:
22,658
Todd R
Author by

Todd R

"If it's not tested, how do you know whether it works?"

Updated on July 09, 2022

Comments

  • Todd R
    Todd R almost 2 years

    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?