Home > Software engineering >  xpath of following sibling which is stored as header and value
xpath of following sibling which is stored as header and value

Time:12-02

I am trying to extract the flavour name - Fizzy Drink which has a label Flavour. so far i tried Xpath - //span[contains(@class, "a-size-base a-text-bold") and text()="Flavour"] which gives me the flavour, I want to extract the value - Fizzy Drink using next sibling. Please help

<tr class="a-spacing-small">
<td class="a-span3">
<span class="a-size-base a-text-bold">Flavour</span>
</td>
<td class="a-span9">
<span class="a-size-base">Fizzy Drink</span>
</td>
</tr>

CodePudding user response:

In xpath, "next sibling" is represented by the following-sibling axis. So in your case:

//td[span[.="Flavour"]]/following-sibling::td//span/text()

should do it.

  • Related