ShockwaveNN
ShockwaveNN

Reputation: 2268

Address elment by number from differnet parents using xpath

So I have this DOM structure

<body>
    <div>
        <a></a>
        <a></a>
    </div>
    <div>
        <a></a>
    </div>
</body>

I can access two first link element by using xpath:

//div/a[1] 
//div/a[2]

And I want to access 3rd link by using same xpath structure (to enumerate them all)

//div/a[3]

But this method fails, because link elements have different parent div's Any way to correct my xpath to access all link elements by it's number?

Upvotes: 1

Views: 33

Answers (1)

BeniBela
BeniBela

Reputation: 16917

You can use parenthesis:

 (//div/a)[3]

Upvotes: 3

Related Questions