Do not convey information solely through icons or symbols.
Language: Java
Framework: Selenium 4
1//Assuming the webpage uses icons or symbols to convey information23import org.openqa.selenium.By;4import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.chrome.ChromeDriver;7import org.openqa.selenium.chrome.ChromeOptions;89public class AccessibilityTesting {10 public static void main(String[] args) {11 //Assuming ChromeDriver is installed in the system12 System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");13 14 //Assuming the webpage is accessible locally15 WebDriver driver = new ChromeDriver();16 17 //Assuming the webpage is hosted remotely with desired capabilities18 /*19 DesiredCapabilities capabilities = DesiredCapabilities.chrome();20 ChromeOptions options = new ChromeOptions();21 options.addArguments("test-type");22 options.merge(capabilities);23 WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options);24 */25 26 //Assuming the webpage uses icon with alt text to convey information27 driver.get("https://example.com");28 WebElement icon = driver.findElement(By.xpath("//img[@alt='icon alt text']"));29 String iconText = icon.getAttribute("alt");30 assert !iconText.isEmpty() : "Icon does not have any alt text to convey information";31 32 //Assuming the webpage uses symbols with text to convey information33 driver.get("https://example.com");34 WebElement symbol = driver.findElement(By.xpath("//span[text()='symbol text']"));35 String symbolText = symbol.getText();36 assert !symbolText.isEmpty() : "Symbol does not have any text to convey information";3738 driver.quit();39 }40}
Language: Python
Framework: Selenium 4
1from selenium import webdriver2from selenium.webdriver.common.keys import Keys34# Assuming the application is a web application56# Local Driver7driver = webdriver.Chrome()89# Remote Client with Desired Capabilities10# driver = webdriver.Remote(command_executor="http://127.0.0.1:4444/wd/hub",11# desired_capabilities={"browserName": "chrome"})1213# Assuming the URL of the web app is https://example.com14driver.get("https://example.com")1516# Finding all the elements that have attribute aria-label17aria_labels = driver.find_elements_by_css_selector("*[aria-label]")1819# Finding all the elements that have attribute aria-labelledby20aria_labelled_bys = driver.find_elements_by_css_selector("*[aria-labelledby]")2122# Iterate through all the elements that have aria-label attribute and check if they have an icon or symbol only23for aria_label in aria_labels:24 if "<i>" in aria_label.get_attribute("innerHTML") or "<svg>" in aria_label.get_attribute("innerHTML"):25 print("Test Case Failed: Information conveyed solely through icons or symbols")2627# Iterate through all the elements that have aria-labelledby attribute and check if they have an icon or symbol only28for aria_labelled_by in aria_labelled_bys:29 if "<i>" in aria_labelled_by.get_attribute("innerHTML") or "<svg>" in aria_labelled_by.get_attribute("innerHTML"):30 print("Test Case Failed: Information conveyed solely through icons or symbols")3132# Close the driver33driver.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