# How to use the Playwright Python API with Axe-core Prerequisites: - [Playwright Python API](https://playwright.dev/python/) - [Axe-core Getting Started](https://github.com/dequelabs/axe-core#getting-started) This doc is a sketch of how to integrate the Playwright Python API with Axe-core. I have not done it myself. I do not cover how to install the Axe-core library. ## Step 1: Inject Axe Inject the Axe-core JavaScript file into the web page that you want to test. Use Playwright's [`page.add_script_tag`](https://playwright.dev/python/docs/api/class-page#page-add-script-tag) method: ```python page.add_script_tag( path="node_modules/axe-core/axe.min.js" ) ``` Again I haven't tested this, but the documentation suggests that when the `add_script_tag` method returns, the Axe-core script should be loaded inside the browser's web page and ready to use. ## Step 2: Run Axe and collect results After the Axe-core script has been injected on the page and once it is ready to use, you can run it via `page.evaluate`: ```python results = page.evaluate("axe.run()") ``` `axe.run()` returns a [JavaScript promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise), and according to the Playwright docs, [`page.evaluate`](https://playwright.dev/python/docs/api/class-page#page-evaluate) waits for the promise to resolve and then returns its value. However, this assumes that the value is serializable. Hopefully, it is. Otherwise, you'll have to write some JavaScript to strip out the unserializable values from the value returned by the `axe.run()` promise. ## Step 3: Do something with the results The [Axe-core results object/dictionary](https://www.deque.com/axe/core-documentation/api-documentation/#results-object) contains information about the results of the accessibility checks that were run against the page. ```python num_violations = len(results["violations"]) assert num_violations == 0, "Axe-core found {num} violations".format( num=num_violations ) ```