When creating a custom interactive widget, consult the ARIA Authoring Practices Document. Use ARIA labels, descriptions, roles, states, and properties to expose information about the component.
Language: Java
Framework: Selenium 4
1//Assuming that we have a web application with custom interactive widgets2//Assuming that we have downloaded the ARIA Authoring practices document and know how to implement them34import org.openqa.selenium.WebDriver;5import org.openqa.selenium.chrome.ChromeDriver;6import org.openqa.selenium.remote.DesiredCapabilities;7import org.openqa.selenium.remote.RemoteWebDriver;8import java.net.URL;910public class AccessibilityTesting {1112 public static void main(String[] args) throws Exception {1314 //Creating a local driver15 WebDriver driver = new ChromeDriver();16 17 //Connecting to a remote client with desired Capabilities18 //Uncomment the code below and replace <REMOTE_CLIENT_URL> with the URL of the remote client19 /*20 DesiredCapabilities capabilities = new DesiredCapabilities();21 capabilities.setCapability("platformName", "Windows 10");22 capabilities.setCapability("browserName", "chrome");23 RemoteWebDriver driver = new RemoteWebDriver(new URL("<REMOTE_CLIENT_URL>"), capabilities);24 */2526 //Assuming we are testing the accessibility of a specific web page with custom interactive widgets27 String url = "https://example.com/accessibility-page";28 driver.get(url);2930 //Assuming we have elements with ARIA attributes on the page31 //For example, we have a button with ARIA role='button', ARIA label='submit', ARIA description='press to submit form'32 //We can use Selenium's findElement() method to locate the element and check its ARIA attributes33 String buttonRole = driver.findElement(By.id("submit-btn")).getAttribute("role");34 String buttonLabel = driver.findElement(By.id("submit-btn")).getAttribute("aria-label");35 String buttonDescription = driver.findElement(By.id("submit-btn")).getAttribute("aria-describedby");3637 //Assuming we have implemented the ARIA attributes correctly, we can check if they match the expected values38 if (buttonRole.equals("button") && buttonLabel.equals("submit") && buttonDescription.equals("press to submit form")) {39 System.out.println("ARIA attributes for custom interactive widget are correctly implemented");40 } else {41 System.out.println("ARIA attributes for custom interactive widget are not correctly implemented");42 }4344 driver.quit();45 }46} 4748//Additional assumptions:49//We have installed the latest version of ChromeDriver and added it to the system's PATH variables50//We have imported the necessary Selenium libraries and set up the project in an IDE like Eclipse or IntelliJ IDEA
Language: Python
Framework: Selenium 4
1#Assumed that the webpage is loaded and the custom interactive widget is present2#Assumed that the Selenium 4 and Chrome driver are installed and added to PATH34from selenium import webdriver5from selenium.webdriver.common.keys import Keys6from selenium.webdriver.common.desired_capabilities import DesiredCapabilities78#Local Driver Connection9driver = webdriver.Chrome()1011#Remote Client Connection12#desired_capabilities = DesiredCapabilities.CHROME13#desired_capabilities['browserName'] = 'chrome'14#desired_capabilities['version'] = 'latest'15#desired_capabilities['platform'] = 'WIN10'16#driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub', desired_capabilities=desired_capabilities)1718#Assuming the custom interactive widget is a button19button = driver.find_element_by_xpath("//button[@id='custom_button']")2021#Check if the button has ARIA role attribute and value is button22assert button.get_attribute('role') == 'button'2324#Check if the button has ARIA label attribute and value is 'Custom Button'25assert button.get_attribute('aria-label') == 'Custom Button'2627#Check if the button has ARIA describedby attribute and value is 'Description for Custom Button'28assert button.get_attribute('aria-describedby') == 'custom_button_description'2930#Check if the button has ARIA haspopup attribute and value is true31assert button.get_attribute('aria-haspopup') == 'true'3233#Check if the button has ARIA pressed attribute and value is false34assert button.get_attribute('aria-pressed') == 'false'3536#Assumed that the button is clicked to initiate an action37button.click()3839#Close the driver40driver.close()
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