For tooltips, follow corresponding ARIA authoring practice.
Language: Java
Framework: Selenium 4
1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.chrome.ChromeDriver;4import org.openqa.selenium.remote.DesiredCapabilities;5import org.openqa.selenium.remote.RemoteWebDriver;67public class TooltipARIA {89 public static WebDriver driver;1011 public static void main(String[] args) {1213 // Assumptions: 14 // This test case is being executed on the latest version of Google Chrome browser15 // The website has tooltips that need to be tested16 // The website is accessible over the internet and is available to test1718 // Setting local driver path19 System.setProperty("webdriver.chrome.driver", "/path/to/local/chromedriver");2021 // Creating instance of ChromeDriver22 driver = new ChromeDriver();2324 // Commented code to connect to remote client with desired capabilities25 // DesiredCapabilities capabilities = DesiredCapabilities.chrome();26 // driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);2728 // Navigating to website for testing29 driver.get("https://www.example.com");3031 // Adding code to perform ARIA authoring practice for tooltips32 // Assuming each tooltip is associated with an element that has attribute [data-tooltip]33 List<WebElement> tooltipElements = driver.findElements(By.cssSelector("[data-tooltip]"));3435 for(WebElement element : tooltipElements) {36 String tooltipText = element.getAttribute("data-tooltip");37 String tooltipID = element.getAttribute("aria-describedby");38 // Assuming that the tooltip content is present in an element with ID same as the tooltipID39 WebElement tooltipContent = driver.findElement(By.id(tooltipID));40 String tooltipContentText = tooltipContent.getText();41 // Assuming that tooltipContentText should be equal to the tooltipText42 assert(text.equalsIgnoreCase(tooltipContentText));43 }4445 // Closing the driver window46 driver.quit();47 }48}
Language: Python
Framework: Selenium 4
1from selenium import webdriver23#Assuming the webpage has tooltips with ARIA tags4#Assuming webdriver is installed and placed in PATH5#Assuming Chrome browser is installed on the local machine67#Using ChromeDriver as the local driver8driver = webdriver.Chrome()910#Use the following code to connect to remote client with desired capabilities11#Assuming Selenium Grid is set up and remote instance details are known12#remote_instance_url = 'http://<remote_ip>:<port>/wd/hub'13#desired_capabilities = {'browserName': 'chrome'}14#driver = webdriver.Remote(remote_instance_url, desired_capabilities)1516#Assuming button with tooltip exists on the webpage17#Clicking on the button to trigger tooltip18button = driver.find_element_by_id('tooltip_button')19button.click()2021#Assuming tooltip is displayed in div with id 'tooltip'22#Checking if the aria-describedby attribute exists on the button element23aria_id = button.get_attribute("aria-describedby")24assert aria_id is not None, "aria-describedby attribute not found on button element"2526#Checking if the corresponding element with id equal to the value of aria-describedby has the 'tooltip' attribute27tooltip = driver.find_element_by_id(aria_id)28assert 'tooltip' in tooltip.get_attribute("class"), "Tooltip ARIA authoring practice not implemented correctly"2930#Close the browser window31driver.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.
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