Accessibility testing : Additional meaning for visually inadequate text

If the visible text alone is not sufficient to convey meaning, use advanced techniques to provide additional meaning, such as ARIA attributes, screen reader-only text, or the title attribute.

Language: Java

Framework: Selenium 4

copy
1/​/​Assumption: The test environment is a webpage where certain text does not convey meaning on its own23import org.openqa.selenium.WebDriver;4import org.openqa.selenium.chrome.ChromeDriver;56public class AccessibilityTesting {7 public static void main(String[] args) {8 /​/​add the path to your local driver9 System.setProperty("webdriver.chrome.driver", "path/​to/​local/​driver");1011 /​/​initialize the driver12 WebDriver driver = new ChromeDriver();1314 /​/​add desired capabilities for remote client15 /​/​DesiredCapabilities capabilities = new DesiredCapabilities();16 /​/​capabilities.setBrowserName("chrome");17 /​/​capabilities.setCapability("version", "87.0.4280.88");18 /​/​capabilities.setCapability("platform", "Windows 10");19 /​/​WebDriver driver = new RemoteWebDriver(new URL("http:/​/​localhost:4444/​wd/​hub"), capabilities);2021 /​/​navigate to the webpage22 driver.get("https:/​/​example.com");2324 /​/​locate the visually inadequate text element using its XPATH25 WebElement element = driver.findElement(By.xpath("/​/​input[@id='example_text']"));2627 /​/​assert that the element has ARIA attributes, screen reader-only text, or the title attribute28 /​/​Assumption: ARIA attributes and screen reader-only text are used to convey additional meaning29 assertTrue(element.getAttribute("aria-label") != null || element.getAttribute("role") != null || !element.getAttribute("hidden").equals("true") || element.getAttribute("title") != null, "Visually inadequate text does not have additional meaning");3031 /​/​close the browser32 driver.quit();33 }34}

Language: Python

Framework: Selenium 4

copy
1#Assumptions: 2#1. The application is a web application. 3#2. The page layout includes various form fields and buttons, including a login button. 45#Imports:6from selenium.webdriver import Chrome7from selenium.webdriver.common.keys import Keys8from selenium.webdriver.common.desired_capabilities import DesiredCapabilities910#Local Driver:11driver = Chrome(executable_path = '[PATH TO CHROMEDRIVER.EXE]')1213#Desired Capabilities for Remote Client:14''' 15capabilities = DesiredCapabilities.CHROME16capabilities['version'] = '84.0.4147.30'17capabilities['platform'] = 'WINDOWS'18capabilities['name'] = 'Accessibility Testing'19'''2021#Test Scenario: Accessibility Testing22#Test Case: Additional meaning for visually inadequate text23#Description: If the visible text alone is not sufficient to convey meaning, 24#use advanced techniques to provide additional meaning, 25#such as ARIA attributes, screen reader-only text, or the title attribute.2627#Open the web application:28driver.get('http:/​/​example.com')2930#Find the field that requires additional meaning:31field = driver.find_element_by_id('field_id')3233#Add ARIA attribute to the field:34driver.execute_script('arguments[0].setAttribute("aria-describedby", "description_id");', field)3536#Add screen reader-only text to the ARIA-describedby:37screen_reader_text = driver.find_element_by_id('description_id')38driver.execute_script('arguments[0].innerHTML = "Additional meaning for visually inadequate text";', screen_reader_text)3940#Add the title attribute to the field:41field.send_keys('Input Data', Keys.TAB)42driver.execute_script('arguments[0].setAttribute("title", "Additional meaning for visually inadequate text");', field)4344#Close the browser:45driver.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