Make sure each web page has a title tag that is descriptive, informative, and unique.
Language: Java
Framework: Selenium 4
1// Assumptions: 2// 1. The Selenium 4 Java Client libraries are installed and configured.3// 2. The web URL of the application under test is provided.45import org.openqa.selenium.WebDriver;6import org.openqa.selenium.chrome.ChromeDriver;7import org.openqa.selenium.chrome.ChromeOptions;8import org.openqa.selenium.remote.DesiredCapabilities;910public class AccessibilityTest {1112 public static void main(String[] args) {13 14 // Set the local Chrome Driver executable path15 System.setProperty("webdriver.chrome.driver", "/path/to/local/chromedriver");1617 // Uncomment the following code for remote execution with desired capabilities18 /*19 DesiredCapabilities capabilities = DesiredCapabilities.chrome();20 ChromeOptions options = new ChromeOptions();21 options.addArguments("--headless");22 capabilities.setCapability(ChromeOptions.CAPABILITY, options);23 WebDriver driver = new RemoteWebDriver(new URL("http://remote-client-url/wd/hub"), capabilities);24 */25 26 // Start a new browser instance using the local driver27 WebDriver driver = new ChromeDriver();2829 // Navigate to the application URL30 driver.get("https://www.example.com");3132 // Verify the page title is descriptive and unique33 String pageTitle = driver.getTitle();34 if (pageTitle == null || pageTitle.isEmpty()) {35 System.out.println("FAIL: Page title is missing or empty.");36 } else {37 if (pageTitle.equalsIgnoreCase("Example - Homepage")) {38 System.out.println("PASS: Page title is descriptive and unique.");39 } else {40 System.out.println("FAIL: Page title is not descriptive or not unique.");41 }42 }43 44 // Close the browser instance45 driver.quit();46 47 }4849}
Language: Python
Framework: Selenium 4
1from selenium import webdriver23#Assuming the webpage uses HTML54#Assuming that the webpage has already been loaded56#Using a local driver7driver = webdriver.Chrome()89#Using a remote driver with desired capabilities10#uncomment the following commented lines and add the desired capabilities accordingly11# from selenium.webdriver.common.desired_capabilities import DesiredCapabilities12# caps = DesiredCapabilities.CHROME.copy()13# caps['platform'] = "WINDOWS"14# caps['version'] = "10"15# driver = webdriver.Remote(16# command_executor='http://localhost:4444/wd/hub',17# desired_capabilities=caps)1819#The following line gets the title of the current page20page_title = driver.title2122#Assuming the title has already been checked and verified before, this test case code will pass23assert page_title is not None and page_title != "", "Page title is empty or None"2425# Assuming the title is descriptive and unique, this test case code will pass26assert "descriptive" in page_title and "unique" in page_title, "Page title is not descriptive or unique"2728driver.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.
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