Question

Consider the following xpath with repeated following-sibling's:

//tr[td[text()='Map']]/td/following-sibling::td/following-sibling::td/preceding-sibling::td/text()", doc, XPathConstants.NODESET)

It has the same result as a single following-sibling:

//tr[td[text()='Map']]/td/following-sibling::td/following-sibling::td/preceding-sibling::td/text()", doc, XPathConstants.NODESET)

Apparently the repeated following-sibling's are treated as duplicates ..? So then how to achieve the effect of "give me the third succeeding sibling" ?

thanks!

Was it helpful?

Solution

Given the following XML:

<tr>
    <td>Map</td>
    <td>First</td>
    <td>Second</td>
    <td>Third</td>
</tr>

these XPaths (second by suggestion from @paul t.)

//tr/td[text()='Map']/following-sibling::td[3]/text()
//tr[td='Map']/td[4]/text()

return 'Third' as expected.

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