Accessibility testing : Inline help text association

When providing inline help text, use aria-describedby to associate the help text with the input.

Language: Java

Framework: Selenium 4

copy
1/​/​Assumptions: 2/​/​ 1. The webpage is a form with input fields for which inline help text is provided.3/​/​ 2. The inline help text is present adjacent to the input element with a unique ID.4/​/​ 3. The webpage uses Selenium 4 for testing and requires the chrome webdriver.5/​/​ 4. The webdriver is downloaded and saved locally.67import org.openqa.selenium.*;8import org.openqa.selenium.chrome.ChromeDriver;9import org.junit.*;10public class AccessibilityTest {11 private WebDriver driver;12 private String chromeDriverPath = "/​path/​to/​chromedriver";1314 @Before15 public void setUp() {16 /​/​ Local chrome driver17 System.setProperty("webdriver.chrome.driver", chromeDriverPath);18 driver = new ChromeDriver();19 /​/​ Remote client with desired capabilities20 /​/​ DesiredCapabilities capabilities = DesiredCapabilities.chrome();21 /​/​ WebDriver driver = new RemoteWebDriver(new URL("http:/​/​localhost:4444/​wd/​hub"),capabilities);22 }2324 @Test25 public void testInlineHelpTextAssociation() {26 /​/​Navigate to webpage27 driver.get("https:/​/​example.com/​form");2829 /​/​Find input element to which inline help text is associated30 WebElement inputElement = driver.findElement(By.id("inputElementID"));3132 /​/​Find the adjacent inline help text element and associate with input using aria-describedby attribute33 WebElement inlineHelpTextElement = driver.findElement(By.id("inlineHelpTextID"));34 inputElement.setAttribute("aria-describedby", inlineHelpTextElement.getAttribute("id"));3536 /​/​Verify aria-describedby attribute is set for input element37 Assert.assertTrue("aria-describedby attribute was not set for input element", inputElement.getAttribute("aria-describedby"));38 }3940 @After41 public void tearDown() {42 /​/​Close the browser43 driver.quit();44 }45}

Language: Python

Framework: Selenium 4

copy
1from selenium import webdriver23# Assuming the application is a web-based UI4# And the input element has an id of 'input-box'5# And the help text element has an id of 'help-text'67# Initializing a local Chrome WebDriver8driver = webdriver.Chrome()910# Alternatively, remote WebDriver connection with desired capabilities11# from selenium.webdriver.remote.webdriver import WebDriver as RemoteWebDriver12# remote_driver = RemoteWebDriver(command_executor='http:/​/​localhost:4444/​wd/​hub', desired_capabilities=desired_capabilities)1314# Navigating to the web page with input and help text15driver.get('https:/​/​example.com')1617# Retrieving the input and help text elements by their ids18input_box = driver.find_element_by_id('input-box')19help_text = driver.find_element_by_id('help-text')2021# Associating the help text with the input element using aria-describedby22input_box.get_attribute('id')23input_box.get_attribute('aria-describedby')24input_box.send_keys('sample input')25input_box.get_attribute('aria-describedby')2627# Closing the browser window28driver.quit()

Disclaimer: Following code snippets and related information have been sourced from GitHub and/or generated using AI code generation tools. LambdaTest takes no responsibility in the accuracy of the code and is not liable for any damages.

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Power Your Software Testing with AI and cloud

Test Intelligently and ship faster. Deliver unparalleled digital experiences for real world enterprises.

Start Free Testing