Links should always be easily identifiable through non-color means, including both default and hover states. The easiest and most conventional way to signify links is underlining.
Language: Java
Framework: Selenium 4
1// Assumption: The web application has links that need to be tested for accessibility.2// Assumption: The web application is accessible through a local server.34import org.openqa.selenium.By;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.chrome.ChromeDriver;8import org.openqa.selenium.chrome.ChromeOptions;910public class AccessibilityTesting {1112 public static void main(String[] args) {1314 // Set the path to the local Chrome Driver15 System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");1617 // Create an instance of ChromeOptions18 ChromeOptions options = new ChromeOptions();1920 // Set the desired capabilities of the remote client, if applicable21 // options.setCapability("platform", "Windows 10");22 // options.setCapability("version", "latest");23 // options.setCapability("browserName", "chrome");2425 // Create a new ChromeDriver instance26 WebDriver driver = new ChromeDriver(options);2728 // Navigate to the web application29 driver.get("http://localhost:8080");3031 // Find all the links on the page32 List<WebElement> links = driver.findElements(By.tagName("a"));3334 // Loop through all the links and check for underlining35 for (WebElement link : links) {36 String text = link.getText();37 String style = link.getAttribute("style");38 if (!style.contains("text-decoration:underline") && !style.contains("text-decoration: underline")) {39 System.out.println("Link " + text + " is not underlined.");40 }41 }4243 // Close the driver44 driver.quit();45 }46}
Language: Python
Framework: Selenium 4
1from selenium import webdriver2from selenium.webdriver.common.keys import Keys3from selenium.webdriver.common.action_chains import ActionChains45# assumption: the website has links for navigation6# create a webdriver object for local driver7driver = webdriver.Chrome()89# creating webdriver object for remote client with desired capabilities10"""11desired_cap = {12 'browserName': 'chrome',13 'version': '91.0',14 'platform': 'WINDOWS',15}16driver = webdriver.Remote(17 command_executor='http://localhost:4444/wd/hub',18 desired_capabilities=desired_cap)19"""2021# assumption: website URL is known22website_url = "https://www.example.com"2324# navigate to website25driver.get(website_url)2627# assumption: all links are present on web page28# find all links on the page29links = driver.find_elements_by_tag_name('a')3031# assumption: links are easily identifiable with non-color means32# check if links are underlined33for link in links:34 # check if link is underlined35 assert "underline" in link.value_of_css_property("text-decoration"), "Link is not underlined"36 37 # check if link is underlined on hover38 hover = ActionChains(driver).move_to_element(link)39 hover.perform()40 assert "underline" in link.value_of_css_property("text-decoration"), "Link is not underlined on hover"41 42driver.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