Vipz
Vipz

Reputation: 207

Get an element from the text of its descendants

I have the text of all the descendants of an element in one line.

How to get the element class="Block" ?

I could find an element with the text of some one descendant, but in another element it can be the same.

1 - It is necessary to use the text of all descendants.

2 - I don't know which tags are the descendants of.

3 - I don't know the elements and descendants positions, they always change

4 - Can be different number of descendants

<!DOCTYPE html>
<html>
<head>
    <title>Test</title>
</head>
<body>
    <div class="AllBlock">
        <div class="Block">
            <span>First text</span> <span>different text</span> <a>first link</a>
        </div>
        <div class="Block">
            <span>Second text</span> <span>different text</span> <a>Second link</a>
        </div>
        <div class="Block">
            <span>Third text</span> <span>different text</span> <a>Third link</a>
        </div>
        <div class="Block">
            <span>Fourth text</span> <span>different text</span> <a>Fourth link</a>
        </div>
        <div class="Block">
            <span>Fifth text</span> <span>different text</span> <a>Fifth link</a>
        </div>
    </div>
</body>
</html>

Upvotes: 1

Views: 206

Answers (1)

Andersson
Andersson

Reputation: 52675

To select node by its space-normalized string value ignoring innerHTML structure, try below:

//div[@class="Block" and normalize-space()="First text different text first link"]

Upvotes: 4

Related Questions