Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file.

## [Unreleased]

- Fixed `generate_report()` raising `TypeError` when a violation targets an element inside shadow DOM (nested target selectors). Shadow DOM targets are now shown as `host >>> element`.

## [0.1.8] - July 24, 2026

- Upgraded axe-core JS version to v4.12.1. You may see the number of violations change as a result, as new axe-core versions sometimes add new rules and update existing ones.
Expand Down
5 changes: 4 additions & 1 deletion axe_playwright_python/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ def generate_snapshot(self):
def __violation_report(self, violation: dict, template: Template) -> str:
nodes_str = ""
for num, node in enumerate(violation["nodes"], start=1):
targets = ", ".join(node["target"])
# Shadow DOM targets are nested lists of selectors (host -> descendant)
targets = ", ".join(
" >>> ".join(t) if isinstance(t, list) else t for t in node["target"]
)
nodes_str += f"\n\n\t{num})\tTarget: {targets}"
snippet = node.get("html").replace("\n", "")
nodes_str += f"\n\t\tSnippet: {snippet}"
Expand Down
26 changes: 26 additions & 0 deletions tests/test_report_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,29 @@ def test_save_results_violations_only(test_results_json):
def test_violations_count(test_results_json):
results = AxeResults(test_results_json)
assert results.violations_count == 2


def test_report_shadow_dom_target():
results = AxeResults(
{
"violations": [
{
"id": "button-name",
"impact": "critical",
"description": "Ensure buttons have discernible text",
"help": "Buttons must have discernible text",
"helpUrl": "https://dequeuniversity.com/rules/axe/4.14/button-name",
"tags": ["wcag2a"],
"nodes": [
{
"target": [["#host", "button"]],
"html": "<button></button>",
"any": [{"message": "Element does not have inner text"}],
}
],
}
]
}
)
report = results.generate_report()
assert "Target: #host >>> button" in report
Loading