1

I am writing the selenium test.

I have a label there "Assign Designer" and the select box followed right after the label. Unfortunetely, select box has the dynamic id and I can not query it by id or any other it's attribute.

Can I build the XPath query that returns "First select tag after text 'Assign Designer'"?

PS. Selenium supports only XPath 1.0

1 Answer 1

3

This would be something like:

//label[text() = 'Assign Designer']/following-sibling::select[1]

Note that:

  • The // shorthand is quite inefficient, because it causes a document-wide scan. If you can be more specific about the label's position, I recommend doing so. If the document is small, however, this won't be a problem.
  • Since I don't know much about Selenium, I used "label". If it is not a <label>, you should use the actual element name, of course. ;-)
  • be sure to include a position predicate ([1], in this case) whenever you use an axis like "following-sibling". It's easily forgotten and if it is, your expressions may produce unexpected results.
Sign up to request clarification or add additional context in comments.

2 Comments

Does 'following-sibling' supported by XPath 1.0 specification?
What a strange question... Have you tried looking it up? w3.org/TR/xpath#axes

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.