axe-selenium-python icon indicating copy to clipboard operation
axe-selenium-python copied to clipboard

Can not set rule disabled via options parameter

Open WallaceChen123 opened this issue 3 years ago • 2 comments

Hi guys,

I am utilizing axe-selenium-python to check our product pages, but I found that I can not set any rule disabled via the options parameter following the axe core guide. options_param = {"rules": {"aria-allowed-attr": {"enabled": "false"}}} results = axe.run(options=options_param) I am not sure whether I made any mistakes or if is there any issue with axe-selenium-python.

WallaceChen123 avatar Dec 05 '22 09:12 WallaceChen123

I know this is a 2 years old comment but since the library is still used and I was looking answer for this same question, here's my two cents:

The issue is due to how dictionary is handled in the run function of axe.py as "enabled" should retain given values as boolean instead of strings.

Here's one example how this could be implemented (you can change this to your axe.py if you never update it :P).

def run(self, context = None, options = None):
  """
  Run axe against the current page.
  
  :param context: which page part(s) to analyze and/or what to exclude.
  :param options: dictionary of aXe options.
  """
  args = []
  
  # If context parameter is passed, add to args
  if context is not None:
      args.append(json.dumps(context))
  
  # If options parameter is passed, add to args
  if options is not None:
      # Convert the options dictionary to a JSON string
      options_json = json.dumps(options)
      args.append(options_json)
  
  # Join the arguments with a comma, if both are provided
  args_str = ", ".join(args)
  
  command = (
      f"var callback = arguments[arguments.length - 1];"
      f"axe.run({args_str}).then(results => callback(results))"
  )
  return self.selenium.execute_async_script(command)

After this you can add rule excludes by passing dicts like this to axe run function as options like in the initial message. {"rules":{"svg-img-alt": {"enabled": False}}} and they should work fine.

I would create a PR for this but I guess it does not make sense before someone starts maintaining the repo once again.

Persipaani avatar Jun 20 '24 09:06 Persipaani

@Persipaani, FWIW, it's good to hear the library is still valid. Once we get word from Mozilla on the transfer progress (issue #192), moving this work to the community, we can begin triaging and implementing improvements.

m8ttyB avatar Jun 20 '24 19:06 m8ttyB