in csharp-selenium-webdriver-sample/SamplePageTests.cs [60:89]
public void TestAccessibilityOfIndividualElements()
{
// Both of these 2 options work equally well; which one to use is a matter of preference.
// Option 1: using Selenium's FindElement to identify the element to test
//
// This can be simpler if your test already had to find the element for earlier assertions, or if you want to test
// an element that is hard to identify using a CSS selector.
IWebElement elementUnderTest = _webDriver.FindElement(By.Id("id-of-example-accessible-element"));
AxeResult axeResultWithAnalyzeWebElement = new AxeBuilder(_webDriver)
.WithTags("wcag2a", "wcag2aa", "wcag21aa")
.Analyze(elementUnderTest);
axeResultWithAnalyzeWebElement.Error.Should().BeNull();
axeResultWithAnalyzeWebElement.Violations.Should().BeEmpty();
// Option 2: using AxeBuilder.Include
//
// This can be simpler if you need to test multiple elements at once or need to deal with <iframe>s.
AxeResult axeResultWithInclude = new AxeBuilder(_webDriver)
.Include("#id-of-example-accessible-element")
.Include(".class-of-example-accessible-element")
.Include("#id-of-iframe", "#id-of-element-inside-iframe")
.WithTags("wcag2a", "wcag2aa", "wcag21aa")
.Analyze();
axeResultWithInclude.Error.Should().BeNull();
axeResultWithInclude.Violations.Should().BeEmpty();
}