Make errors easy to discover, identify, and correct. Identify errors using aria-invalid.
Language: Java
Framework: Selenium 4
1// Assumptions: 2// 1. The application being tested is a web application.3// 2. The application uses aria-invalid to mark invalid input fields.4// 3. The WebDriver is installed and the executable is added to the system PATH.56import org.openqa.selenium.By;7import org.openqa.selenium.WebDriver;8import org.openqa.selenium.WebElement;9import org.openqa.selenium.chrome.ChromeDriver;10import org.openqa.selenium.chrome.ChromeOptions;1112public class AccessibilityTesting {1314 public static void main(String[] args) {15 // Local WebDriver16 System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");17 WebDriver driver = new ChromeDriver();1819 // Remote WebDriver20 // ChromeOptions options = new ChromeOptions();21 // options.setCapability("browserName", "chrome");22 // WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options);2324 // Navigate to the web page being tested25 driver.get("https://example.com");2627 // Find all input elements with aria-invalid attribute28 java.util.List<WebElement> invalidInputs = driver.findElements(By.cssSelector("input[aria-invalid='true']"));2930 // Check that each invalid input is visible and has a description31 for (WebElement input : invalidInputs) {32 if (!input.isDisplayed()) {33 System.out.println("Error: The invalid input is not visible.");34 }35 WebElement description = input.findElement(By.xpath("../p[@class='description']"));36 if (description.getText().isEmpty()) {37 System.out.println("Error: The invalid input does not have a description.");38 }39 }4041 // Close the WebDriver42 driver.quit();43 }4445}
Language: Python
Framework: Selenium 4
1# Assumptions:2# - The website has forms with input fields that can be validated3# - The input fields have an aria-invalid attribute that is set to "true" if the input is invalid45# Import necessary libraries6from selenium import webdriver7from selenium.webdriver.common.keys import Keys8from selenium.webdriver.common.action_chains import ActionChains910# Local driver11driver = webdriver.Firefox()1213# Remote client with desired capabilities14'''15from selenium.webdriver.common.desired_capabilities import DesiredCapabilities16capability = DesiredCapabilities.FIREFOX.copy()17capability['platform'] = "ALL"18capability['version'] = "LATEST"19driver = webdriver.Remote(20 command_executor='http://<REMOTE_URL>/wd/hub',21 desired_capabilities=capability)22'''2324# Navigate to the website25driver.get("http://www.example.com/")2627# Identify input fields with aria-invalid attribute28invalid_fields = driver.find_elements_by_xpath('//*[@aria-invalid="true"]')2930# Assert that no invalid fields exist31assert len(invalid_fields) == 0, "There are invalid fields that need to be corrected" 3233# Close the browser34driver.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