Provide text instructions at the beginning of a form or set of fields that describe the necessary input.
Language: Java
Framework: Selenium 4
1// Assuming the website is a web application that has a form for user input2// and requires the user to provide valid input to proceed3// The objective of this test case is to check if the form has text instructions to guide the user45import org.openqa.selenium.*;6import org.openqa.selenium.chrome.ChromeDriver;78public class AccessibilityTesting {910 public static void main(String[] args) {11 12 // Setting up the ChromeDriver to use local driver and connect to remote client with desired capabilities13 System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");14 WebDriver driver = new ChromeDriver();15 DesiredCapabilities capabilities = DesiredCapabilities.chrome();16 capabilities.setCapability("version", "latest");17 driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);1819 // Navigating to the web page with the form20 driver.get("https://www.example.com/form");2122 // Check if the text instructions are present and visible23 boolean instructionsPresent = driver.findElement(By.xpath("//form//p[contains(text(),'Please enter your valid information')]")).isDisplayed();24 25 // Assert if the text instructions are present and visible26 Assert.assertTrue(instructionsPresent);2728 // Close the browser29 driver.quit();30 }31}
Language: Python
Framework: Selenium 4
1from selenium import webdriver2from selenium.webdriver.common.keys import Keys34#Assuming the website is in English5driver = webdriver.Chrome()6driver.get("http://www.example.com")78#Finding the input fields and their labels9input_fields = driver.find_elements_by_xpath("//input")10labels = driver.find_elements_by_xpath("//label")1112#Creating a dictionary to map the label to the input field13label_to_input = {}14for label in labels:15 input_id = label.get_attribute("for")16 if input_id:17 input_field = driver.find_element_by_id(input_id)18 label_to_input[label.text] = input_field1920#Adding instructions to the labels21for label in label_to_input:22 label_to_input[label].send_keys(label)23 label_to_input[label].send_keys(Keys.TAB)2425#Connecting to remote client26#Assuming the remote client is already set up27desired_capabilities = {'browserName': 'chrome', 'version': 'latest', 'platform': 'WINDOWS', 'name': 'Accessibility testing'}28remote_driver = webdriver.Remote(command_executor='http://localhost:4444/wd/hub', desired_capabilities=desired_capabilities)29remote_driver.get("http://www.example.com")30#Rest of the same code to follow as above
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