Reputation: 587
I'm trying to select partially an element with xpath in my selenium code.
My xpath is
//iron-pages[@id='pages']//span[.='s8718216']
what I want is to select any element starting with s, the element just after span.
I tried this:
//iron-pages[starts-with(span[.='s'])
It doesn't work for me.
Can someone help me.
Upvotes: 0
Views: 69
Reputation: 3625
I think this xpath should work //iron-pages[starts-with(text(),'s')]
Or second try:
//iron-pages[starts-with(.,'s')]
<- .
instead of text()
checks element for more properties. Not only text.
There are many properties that might contain text like innerText
, innerHTML
etc.
EDIT:
I just read your question again. You want to select element right after span
so:
//iron-pages[@id='pages']//span[starts-with(text(),'s')]
<- it will select span
elements starting with text s
.
If you want child elements you can use
//iron-pages[@id='pages']//span//*[starts-with(text(),'s')]
Upvotes: 1
Reputation: 1165
Your xpath should be
//iron-pages[starts-with(span[.='s'])//following-sibling::i[1]
it will get the next element that start with span with text s
Upvotes: 1