Do not identify content based on its color, size, shape, position, sound, or other sensory characteristics.
Language: Java
Framework: Selenium 4
1//Assuming we have a web page under testing and the following code uses Selenium WebDriver and the Chrome browser driver for local testing23import org.openqa.selenium.WebDriver;4import org.openqa.selenium.chrome.ChromeDriver;56public class AccessibilityTesting {7 8 public static void main(String[] args) {9 System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");10 WebDriver driver = new ChromeDriver();11 12 //connect to a remote client with desired capabilities (uncomment as needed)13 //DesiredCapabilities capabilities = DesiredCapabilities.chrome();14 //WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);15 16 //load the web page17 driver.get("https://www.example.com");18 19 //assert that the content is not identified based on its sensory characteristics20 //for example, we can check that certain elements or text are not identified based on color or font size21 //assuming the elements have certain attributes or classes that identify them, e.g. using the CSS selector ".no-sensory-attributes"22 boolean isContentAccessible = driver.findElements(By.cssSelector(".no-sensory-attributes")).size() > 0;23 Assert.assertTrue(isContentAccessible, "Content identified by sensory characteristics");24 25 driver.quit();26 }27}
Language: Python
Framework: Selenium 4
1# Assumptions:2# 1. The website/application being tested is already open in the browser3# 2. The user has already logged in to the application and is on the appropriate page.4# 3. There are no obstructive pop-ups or alerts.56# Required imports7from selenium import webdriver8from selenium.webdriver.common.by import By910# Creating an instance of a local driver11driver = webdriver.Chrome()1213# Connecting to a remote client with desired capabilities instead of using a local driver14'''15from selenium.webdriver.common.desired_capabilities import DesiredCapabilities16capabilities = DesiredCapabilities.CHROME.copy()17# add desired capabilities here18driver = webdriver.Remote(19 command_executor='http://[REMOTE SERVER IP]:[PORT]/wd/hub',20 desired_capabilities=capabilities)21'''2223# Navigating to the appropriate page24driver.get("http://[WEBSITE URL]")2526# Disabling CSS and other styling attributes that could lead to the identification of content based on sensory characteristics27driver.execute_script("document.body.style.cssText = 'color: black !important; background-color: white !important; font-family: Arial !important;'")2829# Checking to see if content is not identified based on sensory characteristics30element = driver.find_element(By.XPATH, "//*[contains(text(),'COLOR')]")31assert element.value_of_css_property("color") != "red"32element = driver.find_element(By.XPATH, "//*[contains(text(),'SIZE')]")33assert element.size["height"] != 034element = driver.find_element(By.XPATH, "//*[@id='shape']")35assert element.get_attribute("style") != "border: 1px solid black;"36element = driver.find_element(By.XPATH, "//source[contains(@src,'meow')]")37assert element.get_attribute("type") != "audio/mp3"3839# Closing 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