Adam Sh
Adam Sh

Reputation: 8577

Xpath - choose the first/second element

I have the next xpath:

//span[text()="Bingo"]/parent::div/parent::div/parent::td/preceding-sibling::td[1]

and it returns two elements.

How I choose one of them (first or second)?

I try:

//span[text()="Bingo"]/parent::div/parent::div/parent::td/preceding-sibling::td[1][1]

But it still gives me two elements.

Upvotes: 0

Views: 2272

Answers (1)

choroba
choroba

Reputation: 241738

Use parentheses over the whole expression, then an index:

(//span[text()="Bingo"]/parent::div/parent::div/parent::td/preceding-sibling::td[1])[1]

Upvotes: 7

Related Questions