Accessibility testing : Stable page content during user input

When a user inputs information or interacts with a control, the page should not cause a change in page content, spawn a new browser window, submit a form, cause further change in focus, or cause any other change that disorients the user. If an input causes such a change, the user must be informed ahead of time.

Language: Java

Framework: Selenium 4

copy
1/​/​ Assumptions: 2/​/​ 1. The web application under test has a form with input fields and controls. 3/​/​ 2. Accessibility testing is required to check stable page content during user input. 4/​/​ 3. The test case is to be automated using Selenium 4 framework with Java language.5/​/​ 4. The local driver is used to run the test case and remote client with desired capabilities can be used if required.67/​/​ Import required libraries8import org.openqa.selenium.By;9import org.openqa.selenium.WebDriver;10import org.openqa.selenium.WebElement;11import org.openqa.selenium.chrome.ChromeDriver;1213/​/​ Set the path of chrome driver executable14System.setProperty("webdriver.chrome.driver", "path/​to/​chromedriver");1516/​/​ Initialize ChromeDriver instance17WebDriver driver = new ChromeDriver();1819/​/​ Navigate to the web application under test20driver.get("https:/​/​example.com");2122/​/​ Wait for page to load23Thread.sleep(5000);2425/​/​ Find the input fields and controls26WebElement inputField1 = driver.findElement(By.id("input1"));27WebElement inputField2 = driver.findElement(By.id("input2"));28WebElement control1 = driver.findElement(By.id("control1"));2930/​/​ Enter data in the input fields and interact with controls31inputField1.sendKeys("input1 value");32control1.click();33inputField2.sendKeys("input2 value");3435/​/​ Verify that stable page content is maintained during user input36if(driver.getPageSource().contains("Page content changed")) {37 System.out.println("Page content changed during user input");38} else {39 System.out.println("Stable page content maintained during user input");40}4142/​/​ Quit the driver instance43driver.quit();4445/​/​ Code for connecting to remote client with desired capabilities46/​/​ Assumptions: 47/​/​ 1. The remote client has been set up with the desired capabilities. 48/​/​ 2. The URL of the remote client is "http:/​/​localhost:4444/​wd/​hub".4950import org.openqa.selenium.remote.DesiredCapabilities;51import org.openqa.selenium.remote.RemoteWebDriver;52import java.net.URL;5354/​/​ Set the desired capabilities for the remote client55DesiredCapabilities capabilities = new DesiredCapabilities();56capabilities.setBrowserName("chrome");57capabilities.setPlatform(Platform.WIN10);5859/​/​ Initialize RemoteWebDriver instance60WebDriver driver = new RemoteWebDriver(new URL("http:/​/​localhost:4444/​wd/​hub"), capabilities);6162/​/​ Use the same code as above to navigate to the web application, find input fields and controls, and verify stable page content.

Language: Python

Framework: Selenium 4

copy
1# Assumption: Application is a web-based application and is accessible via web browser2# Importing necessary libraries3from selenium import webdriver4from selenium.webdriver.common.keys import Keys5from selenium.webdriver.chrome.options import Options6from selenium.webdriver.common.desired_capabilities import DesiredCapabilities78# Creating a chrome options object and adding arguments to make the browser headless9chrome_options = Options()10chrome_options.add_argument("--headless")1112# Creating a local driver instance for Chrome13driver = webdriver.Chrome(options=chrome_options)1415# Creating a desired capabilities object to connect to remote client16remote_capabilities = DesiredCapabilities.CHROME.copy()17remote_capabilities['platform'] = "WINDOWS"18remote_capabilities['version'] = "latest"1920# Remote client URL21remote_url = 'http:/​/​remote.client.url'2223# Create a remote webdriver instance with the desired capabilities and remote URL24remote_driver = webdriver.Remote(command_executor=remote_url, desired_capabilities=remote_capabilities)2526# Navigate to the application URL27driver.get("https:/​/​www.application_url.com")2829# Maximize the browser window30driver.maximize_window()3132# Find the input field element33input_field = driver.find_element_by_name("input_field_name")3435# Enter text into the input field36input_field.send_keys("Test Input")3738# Verify that the page content remains stable during user input39if driver.execute_script("return document.readyState") == "complete":40 print("Page content has not changed during user input")41else:42 print("Page content has changed during user input")4344# Close the local driver instance45driver.quit()4647# Close the remote driver instance48remote_driver.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.

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