When the appearance of text conveys meaning, also use appropriate semantic markup.
Language: Java
Framework: Selenium 4
1//Assuming we are testing a web application23//Connecting to local driver4WebDriver driver = new ChromeDriver();56//Connecting to remote client with desired capabilities7//Assuming we want to test on a remote machine with specific settings8ChromeOptions options = new ChromeOptions();9options.addArguments("--disable-notifications"); //disables any notifications on the remote machine10options.addArguments("--headless"); //runs the browser headless11DesiredCapabilities cap = DesiredCapabilities.chrome();12cap.setCapability(ChromeOptions.CAPABILITY, options);13WebDriver driver = new RemoteWebDriver(new URL("http://remote_address:4444"), cap);1415//Loading the webpage to test16driver.get("https://example.com");1718//Checking for appropriate use of semantic markup for text conveying meaning through appearance19List<WebElement> textElements = driver.findElements(By.xpath("//*[contains(@style,'font-weight:bold')]")); //Assuming text conveyed meaning through bold appearance20for (WebElement element : textElements) {21 String tag = element.getTagName(); //getting the tag name of the element22 if(tag.equals("strong") || tag.equals("em") || tag.equals("u")) { //assuming strong, em, and u tags are appropriate semantic markup for conveying meaning through appearance23 System.out.println("Text with bold appearance has appropriate semantic markup");24 } else {25 System.out.println("Text with bold appearance does not have appropriate semantic markup");26 }27}2829//Closing the driver30driver.close();
Language: Python
Framework: Selenium 4
1from selenium import webdriver2from selenium.webdriver.common.desired_capabilities import DesiredCapabilities34# Local driver5driver = webdriver.Firefox()67# Remote driver with desired capabilities8# desired_caps = DesiredCapabilities.FIREFOX.copy()9# desired_caps['platform'] = 'WINDOWS'10# desired_caps['version'] = '84.0'11# driver = webdriver.Remote(command_executor='http://remoteclient:4444/wd/hub', desired_capabilities=desired_caps)1213# Test case code to check semantic markup for text conveying meaning through appearance14driver.get("https://example.com")15element = driver.find_element_by_xpath("//span[contains(@class, 'important')]")16semantic_tag = element.tag_name17if semantic_tag.lower() != "strong" and semantic_tag.lower() != "em":18 print("FAIL: Semantic markup not used for important text")19else:20 print("PASS: Semantic markup used for important text")2122# Assuming the application has class "important" for important text and only "strong" or "em" tag should be used for semantic markup.
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