0

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.

3
  • You mean any element with text starting with s? Commented Dec 20, 2017 at 14:56
  • Yes Rafal, because it displays a list of element starting with s Commented Dec 20, 2017 at 15:04
  • Check my answer Commented Dec 20, 2017 at 15:11

2 Answers 2

1

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')]

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you Rafael, this solution //iron-pages[@id='pages']//span[starts-with(text(),'s')] works for me.
@kirkdouglas Glad I could help :) Happy coding!
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.