When the color of words, backgrounds, or other content is used to convey information, also include the information in text.
Language: Java
Framework: Selenium 4
1//Assuming that the website has color-based content that conveys information 2//and that the tester has access to the web page source code or has permissions to use browser developer tools to inspect elements34import org.openqa.selenium.WebDriver;5import org.openqa.selenium.WebElement;6import org.openqa.selenium.chrome.ChromeDriver;78public class AccessibilityTest {910 public static void main(String[] args) {11 12 //Setting the system property to use chrome driver13 System.setProperty("webdriver.chrome.driver","path/to/chromedriver");1415 //Creating a new instance of ChromeDriver16 WebDriver driver = new ChromeDriver();1718 //Navigating to the website with color-based content19 driver.get("https://www.example.com/colorbasedcontent");2021 //Finding the WebElement that has color-based content to be tested22 WebElement colorBasedContent = driver.findElement(By.id("colorBasedContentId"));2324 //Checking if the color-based information is conveyed in the text content25 if(colorBasedContent.getAttribute("textContent").contains("Important information")){26 System.out.println("Accessibility Test Passed: Textual information conveyed for color-based content");27 }28 else{29 System.out.println("Accessibility Test Failed: Textual information not found for color-based content");30 }3132 //Quitting the WebDriver session33 driver.quit();3435 // Uncomment the following lines to use remote driver with desired capabilities36 //DesiredCapabilities caps = new DesiredCapabilities();37 //caps.setCapability("browserName", "chrome");3839 //WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), caps);4041 }42}
Language: Python
Framework: Selenium 4
1# Import necessary libraries23from selenium import webdriver4from selenium.webdriver.common.desired_capabilities import DesiredCapabilities56# Define driver path and remote client URL (uncomment if using remote client)78# driver_path = '/path/to/local/driver'9remote_client_url = 'http://remoteclienturl.com/wd/hub'1011# Define desired capabilities (uncomment to use remote client)1213# capabilities = DesiredCapabilities.CHROME14# capabilities['version'] = '86.0'15# capabilities['platform'] = 'WINDOWS'1617# Define test function1819def test_accessibility():20 21 # Initialize driver (uncomment to use local driver)22 23 # driver = webdriver.Chrome(driver_path)24 25 # Initialize driver (uncomment to use remote client)26 27 # driver = webdriver.Remote(command_executor=remote_client_url, desired_capabilities=capabilities)28 29 # Navigate to webpage30 31 # driver.get('https://www.website.com')32 33 # Find all elements with color-based content34 35 color_elements = driver.find_elements_by_xpath("//*[contains(@style,'color:')]")36 37 # Loop through each element and check if text is available38 39 for element in color_elements:40 if element.text == '':41 42 # If text is not available, retrieve aria-label or aria-labelledby attribute43 44 if element.get_attribute('aria-label') is not None:45 print('Aria-label attribute available for element: ', element)46 47 elif element.get_attribute('aria-labelledby') is not None:48 print('Aria-labelledby attribute available for element: ', element)49 50 else:51 print('No textual information available for element: ', element)52 53 # Close driver54 55 driver.quit()56 57# Call the test function5859test_accessibility()
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