@@ -11,20 +11,23 @@ possible. With this in mind, we recommend this order of priority:
11
11
12
12
1 . ** Queries Accessible to Everyone** queries that reflect the experience of
13
13
visual/mouse users as well as those that use assistive technology
14
+ 1 . ` getByRole ` : This can be used to query every element that is exposed in
15
+ the
16
+ [ accessibility tree] ( https://developer.mozilla.org/en-US/docs/Glossary/AOM ) .
17
+ With the ` name ` option you can filter the returned elements by their
18
+ [ accessible name] ( https://www.w3.org/TR/accname-1.1/ ) . This should be your
19
+ top preference for just about everything. There's not much you can't get
20
+ with this (if you can't, it's possible your UI is inaccessible). Most
21
+ often, this will be used with the ` name ` option like so:
22
+ ` getByRole('button', {name: /submit/i}) `
14
23
1 . ` getByLabelText ` : Only really good for form fields, but this is the number
15
24
one method a user finds those elements, so it should be your top
16
25
preference.
17
26
1 . ` getByPlaceholderText ` :
18
27
[ A placeholder is not a substitute for a label] ( https://www.nngroup.com/articles/form-design-placeholders/ ) .
19
28
But if that's all you have, then it's better than alternatives.
20
- 1 . ` getByRole ` : This can be used to query every element that is exposed in
21
- the
22
- [ accessibility tree] ( https://developer.mozilla.org/en-US/docs/Glossary/AOM ) .
23
- With the ` name ` option you can filter the returned elements by their
24
- [ accessible name] ( https://www.w3.org/TR/accname-1.1/ ) . This should be your
25
- top preference for interactive elements such as buttons.
26
29
1 . ` getByText ` : Not useful for forms, but this is the number 1 method a user
27
- finds most non-interactive elements (listitems or divs).
30
+ finds most non-interactive elements (like divs and spans ).
28
31
1 . ` getByDisplayValue ` : The current value of a form element can be useful
29
32
when navigating a page with filled-in values.
30
33
1 . ** Semantic Queries** HTML5 and ARIA compliant selectors. Note that the user
0 commit comments