Question

I have the following HTML snippet:

   <divv id="items">
        <trr>
            <td>
                <p>Cars</p>
                <a>Toyota</a>
                <a>Opel</a>
                <a>Audi</a>
            </td>
        </tr>
        <tr>
            <td>
                <p>Planes</p>
                <a>A320</a>
                <a>B787</a>
                <a>B767</a>
            </td>
        </tr>
    <div/>

What I want is to create a XPath query so I can retrieve only the Cars.
Currently I am using this: //div[@id='items']/tr/td. But with this I get also the Plane items. I do not know how to test for the 'p' tag.

Anyone can help me ?
Thanks.

Was it helpful?

Solution 2

If picking the first group is enough, then you can use:

//div[@id='items']/tr/td[1]

OTHER TIPS

//div[@id='items']/tr/td[p='Cars']

The last predicate tests the existence of a <p> child element with Cars text content and thus filters out the <td> with <p>Planes</p>.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top