Skip to main content

elementFilters

tip

Cypress Accessibility is a paid add-on. Schedule a demo today and see how easy it is to enhance your accessibility testing while speeding up your development process.

info

Note: setting elementFilters impacts both Accessibility and UI Coverage reports. Nesting this property under an accessibility or uiCoverage key is supported, if you need to split them up.

The elementFilters property allows you to specify selectors for elements that should be excluded from Cypress Accessibility.

The first elementFilters rule to match the selector property determines whether or not an element is included or excluded from the report. Elements that do not match any rules are included by default.

Syntax - globally applied to both UI Coverage and Cypress Accessibilityโ€‹

{
"elementFilters": [
{
"selector": string,
"include": boolean
}
]
}

Syntax - accessibility-specificโ€‹

{
"accessibility": {
"elementFilters": [
{
"selector": string,
"include": boolean
}
]
}
}

elementFiltersโ€‹

Optional. Object[]

An array of objects specifying the elements to exclude from Cypress Accessibility. Each object can have the following properties:

selectorโ€‹

Required. String (CSS Selector)

Used to match elements.

includeโ€‹

Optional. Boolean

Default: true

A boolean that represents whether or not a matched element should be included in Cypress Accessibility.

Examplesโ€‹

Excluding a specific elementโ€‹

Configโ€‹

{
"elementFilters": [
{
"selector": "#button-2",
"include": false
}
]
}

HTMLโ€‹

<body>
<button id="button-1">Included</button>
<button id="button-2">Excluded</button>
</body>

Elements shown in UIโ€‹

#button-1

Excluding all elements in a containerโ€‹

Configโ€‹

{
"elementFilters": [
{
"selector": "footer *",
"include": false
}
]
}

HTMLโ€‹

<body>
<main>
<button id="start">Included</button>
</main>
<footer>
<a href="#">Excluded</a>
</footer>
</body>

Elements shown in UIโ€‹

#start

Including only elements in a containerโ€‹

Configโ€‹

{
"elementFilters": [
{
"selector": "#form *",
"include": true
},
{
"selector": "*",
"include": false
}
]
}

HTMLโ€‹

<body>
<form id="form">
<input id="name" />
</form>
<footer>
<a href="#">Excluded</a>
</footer>
</body>

Elements shown in UIโ€‹

#name