DEV Community

Mat
Mat

Posted on

2

A quick way to run axe-core from python

I used this code snippet today to run axe-core from a python selenium test. It calls out to the command line interface, using npx so I don't have to worry about managing node packages:

    def check_for_accessibility_issues(self):
        command = ["npx", "@axe-core/cli", "-q", self.selenium.current_url]
        output = subprocess.run(command, capture_output=True, text=True)
        self.assertEqual(output.returncode, 0, output.stdout)
Enter fullscreen mode Exit fullscreen mode

This should work with anything that runs your app in a browser, not just selenium.

Axe is an automated tool to detect some (but not all) web accessibility issues. It's not a substitute for actual usability testing with real people, but it's still useful. For a rough idea of what it can do, check out this blog post: Axe-Core vs PA11y. In the author's testing, axe-core detected 27% of known issues on a test page.

I was originally hoping to use axe-selenium-python for this. It uses selenium's execute_script to inject the axe javascript into the page, similar to this method. Unfortunately, axe-selenium-python has been unmaintained since its author left mozilla. It looks like some nice people are going to take this over, but I wanted a workaround in the meantime.

Note: There is also Deque DevTools, which appears to have python bindings, but this is not open source. 😞

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay