These guidelines should help you to write high quality selectors.
Selectors SHOULD be written in CSS instead of XPath whenever possible
CSS is generally easier to read than XPath. For example,
//*[@id="foo"] in XPath can be expressed as simply as
#foo in CSS.
See this XPath Cheatsheet for more examples.
XPath selectors SHOULD NOT use
This would fail if the attribute was
Instead you SHOULD use
contains(@attribute, "foo") where
@attribute is any valid attribute such as
CSS and XPath selectors SHOULD be implemented in their most simple form
CSS and XPath selectors SHOULD avoid making use of hardcoded indices
Instead you SHOULD parameterize the selector.
CSS and XPath selectors MUST NOT reference the
@data-bind attribute is tied to a specific framework, it should not be used for selectors. If Magento decides to use a different framework then these
@data-bind selectors would break.