Skip to content

Commit e9647eb

Browse files
committed
MQE-1623: Add selector best practices to devdocs
1 parent 0232087 commit e9647eb

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/selectors.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Selectors
2+
3+
The tips and tricks below will help you to write high quality selectors.
4+
5+
### Selectors SHOULD be written in CSS instead of Xpath whenever possible.
6+
7+
### Xpath selectors SHOULD NOT use `@attribute="foo"` instead you SHOULD use `contains(@attribute, "foo")` where `@attribute` is any attribute such as `@text` or `@class` for example.
8+
9+
### CSS and Xpath selectors SHOULD be implemented in their most simple form.
10+
11+
* <span class="color:green">GOOD:</span> `#foo`
12+
* <span class="color:red">BAD:</span> `button[contains(@id, "foo")]`
13+
14+
### CSS and Xpath selectors SHOULD avoid making use of hardcoded indices. Instead you SHOULD parameterize the selector.
15+
16+
* <span class="color:green">GOOD:</span> `.foo:nth-of-type({{index}})`
17+
* <span class="color:red">BAD:</span> `.foo:nth-of-type(1)`
18+
19+
* <span class="color:green">GOOD:</span> `button[contains(@id, "foo")][{{index}}]`
20+
* <span class="color:red">BAD:</span> `button[contains(@id, "foo")][1]`
21+
22+
* <span class="color:green">GOOD:</span> `#actions__{{index}}__aggregator`
23+
* <span class="color:red">BAD:</span> `#actions__1__aggregator`
24+
25+
### CSS and XPath selectors MUST NOT reference the `@data-bind` attribute.

0 commit comments

Comments
 (0)