@@ -187,8 +187,12 @@ cy.findByLabelText('username').should('exist')
187187
188188<!-- END_DOCUSAURUS_CODE_TABS-->
189189
190- It will NOT find the input node for label text broken up by elements. For this
191- case, you can provide a ` selector ` in the options:
190+ It will NOT find the input node for label text broken up by elements. You can
191+ use ` getByRole('textbox', { name: 'Username' }) ` instead which is robust against
192+ switching to ` aria-label ` or ` aria-labelledby ` .
193+
194+ If it is important that you query an actual ` <label> ` element you can provide a
195+ ` selector ` in the options:
192196
193197``` html
194198<label > <span >Username</span > <input /> </label >
@@ -590,6 +594,7 @@ getByRole(
590594 options ?: {
591595 exact?: boolean = true ,
592596 hidden?: boolean = true ,
597+ name?: TextMatch ,
593598 normalizer?: NormalizerFn ,
594599 }): HTMLElement
595600```
@@ -604,6 +609,24 @@ Library uses `aria-query` under the hood to find those elements by their default
604609ARIA roles, you can find in their docs
605610[ which HTML Elements with inherent roles are mapped to each role] ( https://github.com/A11yance/aria-query#elements-to-roles ) .
606611
612+ You can query the returned element(s) by their
613+ [ accessible name] ( https://www.w3.org/TR/accname-1.1/ ) . The accessible name is
614+ for simple cases equal to e.g. the label of a form element, or the text content
615+ of a button, or the value of the ` aria-label ` attribute. It can be used to query
616+ a specific element if multiple elements with the same role are present on the
617+ rendered content. For an in-depth guide check out
618+ [ "What is an accessible name?" from ThePacielloGroup] ( https://developer.paciellogroup.com/blog/2017/04/what-is-an-accessible-name/ ) .
619+ If you only query for a single element with ` getByText('The name') ` it's
620+ oftentimes better to use ` getByRole(expectedRole, { name: 'The name' }) ` . The
621+ accessible name query does not replace other queries such as ` *ByAlt ` or
622+ ` *ByTitle ` . While the accessible name can be equal to these attributes, it does
623+ not replace the functionality of these attributes. For example
624+ ` <img aria-label="fancy image" src="fancy.jpg" /> ` will be returned for both
625+ ` getByAlt('fancy image') ` and ` getByRole('image', { name: 'fancy image' }) ` .
626+ However, the image will not display its description if ` fancy.jpg ` could not be
627+ loaded. Whether you want assert this functionality in your test or not is up to
628+ you.
629+
607630If you set ` hidden ` to ` true ` elements that are normally excluded from the
608631accessibility tree are considered for the query as well. The default behavior
609632follows https://www.w3.org/TR/wai-aria-1.2/#tree_exclusion with the exception of
0 commit comments