Accessibility testing : Meaningful source order for content

Ensure that the source order presents content meaningfully. When the page is viewed without styles, all content on the page should still appear in a meaningful and logical order.

Language: Java

Framework: Selenium 4

copy
1/​/​Assumptions: The webpage's content is structured in a logical order.2/​/​The developer has followed a logical sequence while designing the web page.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.remote.DesiredCapabilities;9import org.openqa.selenium.remote.RemoteWebDriver;1011public class AccessibilityTesting {1213 public static void main(String[] args) {1415 /​/​set chrome driver path16 System.setProperty("webdriver.chrome.driver", "/​path/​to/​chromedriver");1718 /​/​create a new instance of the chrome driver19 WebDriver driver = new ChromeDriver();2021 /​/​connect to remote client with desired capabilities (uncomment to use)22 /​/​DesiredCapabilities capabilities = DesiredCapabilities.chrome();23 /​/​WebDriver driver = new RemoteWebDriver(new URL("http:/​/​host:port/​wd/​hub"), capabilities);2425 /​/​navigate to the webpage26 driver.get("https:/​/​www.example.com");2728 /​/​get the page source without styles29 String pageSource = driver.findElement(By.tagName("html")).getAttribute("textContent");3031 /​/​check the source order for meaning and log the result32 if(pageSource.contains("first content") && pageSource.contains("second content") && pageSource.contains("third content")) {33 System.out.println("Meaningful source order for content: Passed");34 } else {35 System.out.println("Meaningful source order for content: Failed");36 }37 38 /​/​close the driver39 driver.quit();40 }41}

Language: Python

Framework: Selenium 4

copy
1# Assumptions: 2# - The web page is loaded successfully without any errors3# - Local driver is used for testing, but below is the commented code 4# to connect to a remote client with desired capabilities if needed56from selenium import webdriver7from selenium.webdriver.common.keys import Keys8from selenium.webdriver.common.desired_capabilities import DesiredCapabilities910# desired_capabilities = DesiredCapabilities.CHROME.copy()11# desired_capabilities['version'] = '92.0'12# desired_capabilities['enableVNC'] = True 13# driver = webdriver.Remote(14# command_executor='http:/​/​localhost:4444/​wd/​hub',15# desired_capabilities=desired_capabilities16# )1718# Launch browser and the webpage19driver = webdriver.Chrome()20driver.get("http:/​/​mywebsite.com")2122# Check the source order of the content23src_order = driver.find_elements_by_xpath("/​/​*")24is_ordered = True25for i in range(1, len(src_order)):26 prev_tag = src_order[i-1].tag_name27 cur_tag = src_order[i].tag_name28 if prev_tag == 'header' and cur_tag == 'nav':29 is_ordered = False30 break31 elif prev_tag == 'nav' and cur_tag == 'header':32 is_ordered = False33 break34 elif prev_tag == 'footer' and cur_tag != 'header' and cur_tag != 'nav':35 is_ordered = False36 break3738# Check if the source order is meaningful and logical39assert is_ordered, "Invalid source order"4041# Close the browser42driver.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.

Accelerate Your Automation Test Cycles With LambdaTest

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.

Try LambdaTest

Power Your Software Testing with AI and cloud

Test Intelligently and ship faster. Deliver unparalleled digital experiences for real world enterprises.

Start Free Testing