Query html tag with XPath
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
This would be something like:
//label[text() = 'Assign Designer']/following-sibling::select
- 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 (
, 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.