Rich Stevens
Rich Stevens

Reputation: 609

XPATH - grab content of div after named element

There are a number of labels, I want to specify them in xpath and then grab the text after them, example:

<div class="info-row">
    <div class="info-label"><span>Variant:</span></div>
        <div class="info-content">
            <p>750 ml</p>
        </div>
    </div>

So in this case, I want to say "after the span named 'Variant' grab the p tag:

Result: 750ml

I tried:

//span[text()='Variant:']/following-sibling::p

and variations of this but to no avail.

Upvotes: 2

Views: 53

Answers (1)

alexanches1001
alexanches1001

Reputation: 96

'following-sibling' function selects all siblings after the current node, there no siblings for span with text 'Variant:', and correct to search siblings for span parent.

Here is an example which will work

//span[text()='Variant:']/ancestor::div[@class="info-label"]/following-sibling::div/p

Upvotes: 1

Related Questions