Skip to content

Commit

Permalink
Merge pull request #399 from magento/MQE-1675
Browse files Browse the repository at this point in the history
MQE-1675: Remove 'Build selectors with appropriate specificity' from …
  • Loading branch information
tomreece authored Jul 29, 2019
2 parents 3e8ee44 + 62bdb2c commit b6c1e8a
Showing 1 changed file with 0 additions and 27 deletions.
27 changes: 0 additions & 27 deletions docs/tips-tricks.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,33 +345,6 @@ BAD:
<element name="productName" type="input" selector=".admin__field[data-index=name] input"/>
```

### Build selectors with appropriate specificity

Selectors that are too general might sweep up unexpected elements.
When possible, select the first parent tag and then specify the desired element within that selection.

**Why?** Elements that are overly specific are less flexible and may fail if unexpected DOM changes occur. It also reduces the amount of the DOM it needs to parse.

<span style="color:green">
GOOD:
</span>

```html
form[name='myform'] > input[name='firstname']

//*[@id='container'][@class='dashboard-title']
```

<span style="color:red">
BAD:
</span>

```html
input[name='firstname']

//*[@id='container']/*[@class='dashboard-advanced-reports']/*[@class='dashboard-advanced- reports-description']/*[@class='dashboard-title']
```

## General tips

### Use data references to avoid hardcoded values
Expand Down

0 comments on commit b6c1e8a

Please sign in to comment.