jacobcan118
jacobcan118

Reputation: 9109

find the specified element from sibling xpath

How can I specify the element right next to '>' by xpath by not using text? In my case, I only want element of "n" I have build

driver.find_element_by_xpath('//div/div/*[contains(text(),">")]/preceding-sibling::a')

but I get all of the sibling nodes of element ">" like 1 ,2 ,3, n

<div >
    <div >
    <a > 1 < /a >
    <a > 2 < /a >
    <a > 3 < /a >
    <a > n < /a >
    <a > > < / a >
    < / div >
< / div >

Upvotes: 0

Views: 63

Answers (1)

Andersson
Andersson

Reputation: 52695

You cant try below XPath to select the first preceding sibling of link with text " > ":

//a[normalize-space()=">"]/preceding-sibling::a[position()=1]

Upvotes: 2

Related Questions