When conveying a status message, use ARIA live regions or ARIA alerts to announce the message to screen reader users.
Language: Java
Framework: Selenium 4
1// Assuming we have a website with login functionality that displays status messages.23// Create instance of local driver4WebDriver driver = new ChromeDriver();56// Use the website url7driver.get("https://example.com/account");89// maximize the window for better visibility10driver.manage().window().maximize();1112// Get the status message element13WebElement statusMessage = driver.findElement(By.id("status-message"));1415// Check if the status message is visible to screen reader users16Boolean isAccessible = (Boolean) ((JavascriptExecutor) driver).executeScript("return arguments[0].getAttribute('aria-live') === 'assertive';",statusMessage);1718// If the status message is not accessible, throw fail19if (!isAccessible) {20 Assert.fail("Status message is not accessible to screen reader users!");21}2223// Add commented code to connect to remote client with desired capabilities24/*25DesiredCapabilities capabilities = new DesiredCapabilities();26capabilities.setCapability("browserName", "chrome");27capabilities.setCapability("version", "latest");28capabilities.setCapability("platform", "Windows 10");29capabilities.setCapability("screenResolution", "1920x1080");3031WebDriver driver = null;32try {33 driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);34} catch (MalformedURLException e) {35 e.printStackTrace();36}37*/
Language: Python
Framework: Selenium 4
1# Assumptions:2# - Our website has status messages that need to be announced to screen reader users3# - We are using Selenium 4 WebDriver in Python to automate our accessibility testing45from selenium import webdriver6from selenium.webdriver.common.desired_capabilities import DesiredCapabilities78# Set the desired capabilities for remote client9#desired_capabilities = DesiredCapabilities.CHROME.copy()10#desired_capabilities['acceptInsecureCerts'] = True11#desired_capabilities['browserName'] = 'chrome'1213# Connect to remote client with desired capabilities14#driver = webdriver.Remote(15# command_executor='http://localhost:4444/wd/hub',16# desired_capabilities=desired_capabilities17#)1819# Start local driver20driver = webdriver.Chrome()2122# Navigate to our website23driver.get('https://www.example.com')2425# Assume the status message is displayed on the website26status_message = driver.find_element_by_id('status_message')2728# Use ARIA live region or ARIA alert to announce the message to screen reader users29status_message.send_keys('\ue004') # Send ARIA live region alert3031# Close the browser32driver.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.
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.
Test Intelligently and ship faster. Deliver unparalleled digital experiences for real world enterprises.
Start Free Testing