Can you target xpath in pa11y?

296 Views Asked by At

Doing ADA Testing and was wondering if you can target xpath for Pa11y's actions.

For instance: "click element xpath",

I only ask because there are multiple elements on the page with the same target. No unique identifiers to tell pa11y what to click.

1

There are 1 best solutions below

0
On BEST ANSWER

It's not possible to use XPath queries for Pa11y Actions — all of them rely on CSS Selectors instead.

(Specifically, they use document.querySelector under the hood).

Of course with CSS Selectors you can achieve a lot of the same things that XPath can even when there's no unique identifier available; e.g. by using sibling selectors like :nth-of-type. But there is no way to select backwards up the DOM from a child selector to its parent using CSS Selectors.