axe-devtools-api Python API Reference

This page is not available in the language you requested. You have been redirected to the English version of the page.
Link to this page copied to clipboard

API reference for the axe-devtools-api Python package for injecting and running axe-core

Not for use with personal data

Provides an API with which to inject and run axe-core against a web page.

axe_devtools_api.Axe

Configures how axe-core is run and runs it against the page.

report = Axe(page).with_rules("document-title", "label").analyze()

Axe(page, report_configuration=None, axe_source=None)

Initialize an Axe instance with a browser adapter and optional configuration.

page: A browser adapter, such as an AxeDriver instance from axe-devtools-selenium.

report_configuration: Optional. A report configuration object.

axe_source: Optional. A string of axe-core source code to use instead of the bundled version.

analyze()

Inject axe-core into the page and run the accessibility analysis.

Returns a Results object. See Generating Reports With Python for the full Results API and how to configure report metadata.

report = Axe(page).analyze()

including(*selector)

Specify part of the page for axe-core to analyze.

selector: One or more CSS selectors for elements to include.

Returns this object for chaining.

report = Axe(page).including(".sidebar-frame", ".some-class").analyze()

excluding(*selector)

Specify part of the page for axe-core to skip during analysis.

selector: One or more CSS selectors for elements to exclude.

Returns this object for chaining.

report = Axe(page).excluding(".iframe1", ".third-party-ad").analyze()

with_rules(*rules)

Specify rules (by ID) for axe-core to run. Only the specified rules are used. This option is incompatible with with_tags.

rules: One or more rule IDs. See Rule Descriptions for a list of valid IDs.

Returns this object for chaining.

Raises RuntimeError if called together with with_tags on the same instance.

report = Axe(page).with_rules("document-title", "label").analyze()

with_tags(*tags)

Specify rules (by tag) for axe-core to run. Only the specified rules are used. This option is incompatible with with_rules.

tags: One or more tag names. See axe-core tags for a list of valid tags.

Returns this object for chaining.

Raises RuntimeError if called together with with_rules on the same instance.

report = Axe(page).with_tags("best-practice", "wcag2a").analyze()

disabling_rules(*rules)

Disable specific rules from the axe-core run.

rules: One or more rule IDs.

Returns this object for chaining.

report = Axe(page).disabling_rules("html-has-lang", "label").analyze()

run_options(options)

Specify runOptions to pass to axe-core when calling axe.run.

options: Options object to pass to axe-core.

Returns this object for chaining.

options = {"iframes": False}
report = Axe(page).run_options(options).analyze()

configure(spec)

Configure axe-core via axe.configure.

spec: Spec object to pass to axe.configure.

Returns this object for chaining.

report = Axe(page).configure(spec).analyze()

without_iframe_sandboxes()

Remove the sandbox attribute from iframes so that axe-core can run inside them.

Returns this object for chaining.

report = Axe(page).without_iframe_sandboxes().analyze()

with_config_file(config_path)

Set the path to a ruleset config file. The default path is config/axe-ruleset.json, or the value of the $AXE_RULESET_PATH environment variable if set.

config_path: Path to the config file.

Returns this object for chaining.

report = Axe(page).with_config_file("path/to/file.json").analyze()

with_ruleset(ruleset_id, enable_best_practices=False)

Use a specific ruleset for the axe-core run.

ruleset_id: ID of the ruleset to use. Available rulesets: wcag2, wcag2.1, wcag2.2, wcag2aaa, wcag2.1aaa, wcag2.2aaa, 508, en301549, ttv5, rgaav4.

enable_best_practices: Whether to enable rules tagged best-practice. Defaults to False.

Returns this object for chaining.

report = Axe(page).with_ruleset("508").analyze()

set_legacy_mode(state=True)

Use axe.run instead of axe.runPartial. Has cross-origin implications.

state: Whether to enable legacy mode. Defaults to True.

Returns this object for chaining.

report = Axe(page).set_legacy_mode().analyze()

Usage Service

Gain insight into Axe DevTools usage trends within your organization. By default the usage service is disabled. The default URL is https://usage.deque.com.

Usage service environment variables

The following environment variables configure the usage service.

Environment Variable Type
AXE_IS_LOGGED_IN Boolean
AXE_KEYCLOAK_ID String
AXE_USER_ID String
AXE_SESSION_ID String
AXE_USER_STATUS String
AXE_USER_JOB_ROLE String
AXE_DISTINCT_ID String
AXE_IS_DEV_INSTANCE Boolean
AXE_ORGANIZATION String
AXE_APPLICATION String
AXE_METRICS_URL String
AXE_TRACK_USAGE Boolean

enable_tracking(state)

Opt in or out of sending data to the usage service.

state: Whether tracking is enabled.

Returns this object for chaining.

report = Axe(page).enable_tracking(True).analyze()

set_tracking_url(url)

Set where usage metrics data are sent.

url: URL where data will be sent.

Returns this object for chaining.

report = Axe(page).set_tracking_url("https://usage.deque.com").analyze()

set_distinct_id(id)

Set the distinct ID used when sending usage metrics.

id: Distinct ID to send.

Returns this object for chaining.

report = Axe(page).set_distinct_id("SOMEUUID").analyze()