Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MQE-1675: Remove 'Build selectors with appropriate specificity' from … #399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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