CodexBloom - Programming Q&A Platform

Selenium WebDriver failing to interact with ARIA roles in a React app for accessibility testing

πŸ‘€ Views: 0 πŸ’¬ Answers: 1 πŸ“… Created: 2025-09-09
selenium accessibility react JavaScript

I'm working through a tutorial and I'm performance testing and This might be a silly question, but This might be a silly question, but While developing an MVP that prioritizes accessibility, I’ve run into a snag with Selenium WebDriver... My team has implemented various ARIA roles to enhance screen reader support for our React application, but it seems that the elements with ARIA attributes aren't being recognized during our automated tests. I've tried using the `By.cssSelector` and `By.xpath` methods to locate these elements. For instance: ```javascript let button = driver.findElement(By.cssSelector('[role="button"]')); ``` However, the WebDriver fails to interact with it, likely because the element is not initially in the DOM or is off-screen. We’re using Selenium 4.0.0 with ChromeDriver 120, and I’ve ensured that all necessary permissions are set for the browser. In another attempt, I added explicit waits: ```javascript const { WebDriverWait, ExpectedConditions } = require('selenium-webdriver'); let wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.elementToBeClickable(button)); ``` Despite these efforts, the interaction does not succeed. I even inspected the elements manually in Chrome DevTools to confirm their presence and visibility. The screen readers read out the ARIA roles correctly, indicating that the implementation is sound, yet WebDriver struggles to interact with them. Are there any known issues with Selenium and ARIA attributes or specific configurations that I may have overlooked? Also, should I be considering different approaches for testing accessibility in this context, or am I missing something fundamental in my WebDriver interactions? This is part of a larger service I'm building. Any help would be greatly appreciated! My development environment is Ubuntu. How would you solve this? I'm working in a Windows 11 environment. Is there a better approach? How would you solve this? I'm on Linux using the latest version of Javascript. Cheers for any assistance! Thanks for taking the time to read this!