Accessibility testing : Autocomplete attribute for form fields

If a form field asks for information about the user and if there is an appropriate HTML autocomplete attribute, include that autocomplete attribute.

Language: Java

Framework: Selenium 4

copy
1/​/​Assuming the application is a web application23import org.openqa.selenium.By;4import org.openqa.selenium.Keys;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;10import java.net.URL;1112public class AutocompleteTest {1314 public static void main(String[] args) throws Exception {1516 /​/​Assuming the URL of the web app to be tested17 String url = "http:/​/​example.com/​";1819 /​/​Assuming the local driver for Chrome installed20 System.setProperty("webdriver.chrome.driver", "/​path/​to/​chromedriver");2122 /​/​Connecting to the local driver23 WebDriver driver = new ChromeDriver();2425 /​/​Adding comments to connect to remote client with desired capabilities26 /​*27 DesiredCapabilities capabilities = DesiredCapabilities.chrome();28 capabilities.setCapability("version", "latest");29 capabilities.setCapability("platform", "WINDOWS");30 RemoteWebDriver driver = new RemoteWebDriver(new URL("http:/​/​localhost:4444/​wd/​hub"), capabilities);31 */​3233 /​/​Assuming the login page of the web app has a form field with id 'username'34 WebElement inputElement = driver.findElement(By.id("username"));3536 /​/​Assuming the form field has an autocomplete attribute defined as 'username'37 String autocompleteValue = inputElement.getAttribute("autocomplete");3839 if (autocompleteValue.equals("username")) {40 System.out.println("Test case passed. Autocomplete attribute for form fields is present.");41 } else {42 System.out.println("Test case failed. Autocomplete attribute for form fields is not present.");43 }4445 /​/​Closing the driver46 driver.quit();47 }48}

Language: Python

Framework: Selenium 4

copy
1from selenium.webdriver import Chrome2from selenium.webdriver.common.keys import Keys34# Assuming the web page has form fields that ask for user information5# and that there are appropriate autocomplete attributes available67# Using local driver8driver = Chrome()910# Connecting to remote client with desired capabilities11# Uncomment the following code to connect to remote client12# from selenium.webdriver.common.desired_capabilities import DesiredCapabilities13# capabilities = DesiredCapabilities.CHROME.copy()14# driver = Chrome(command_executor='http:/​/​{remote_client_IP}:4444/​wd/​hub', desired_capabilities=capabilities)1516# Assuming the form field has id 'user'17user_field = driver.find_element_by_id('user')1819# Checking for autocomplete attribute20autocomplete_attribute = user_field.get_attribute('autocomplete')2122if autocomplete_attribute is not None:23 print('Test case passed')24else:25 print('Test case failed')

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