Do not provide any content that flashes more than three times in any 1-second period.
Language: Java
Framework: Selenium 4
1//Assuming driver is already configured and page is loaded23//Checking for any flashing content4List<WebElement> flashingContent = driver.findElements(By.xpath("//*[contains(@style, 'animation') or contains(@style, 'transition') or contains(@style, 'flash')]"));56//Looping through each element7for(WebElement element : flashingContent) {8 //Checking for flashing frequency9 String styleAttr = element.getAttribute("style");10 int count = 0;11 while(styleAttr.contains("flash")) {12 count++;13 styleAttr = styleAttr.replaceFirst("flash", "");14 }15 if(count > 3) {16 //If more than 3 flashes per second17 System.out.println("Content flashing more than three times in one-second period!");18 break;19 }20}2122//Code for connecting to remote client with desired capabilities23//Assuming RemoteWebDriver is being used24DesiredCapabilities capabilities = new DesiredCapabilities();25//specifying desired capabilities26RemoteWebDriver driver = new RemoteWebDriver(new URL("<url_of_remote_machine>"), capabilities);
Language: Python
Framework: Selenium 4
1# Assume the Selenium WebDriver is installed23# Import required modules4from selenium import webdriver5from selenium.webdriver.common.by import By6from selenium.webdriver.support.ui import WebDriverWait7from selenium.webdriver.support import expected_conditions as EC89# Set up Chrome browser options10chrome_options = webdriver.ChromeOptions()11chrome_options.add_argument('--no-sandbox')12chrome_options.add_argument('--disable-dev-shm-usage')13chrome_options.add_argument('--disable-gpu')1415# Create a new Chrome browser instance16driver = webdriver.Chrome(options=chrome_options)1718# Add desired capabilities to connect to remote client19# desired_capabilities = {20# "browserName": "chrome",21# "version": "latest",22# "platform": "WINDOWS",23# "screenResolution": "1920x1080",24# "name": "Accessibility testing"25# }26# driver = webdriver.Remote(27# command_executor='http://<remote-client-ip>:4444/wd/hub',28# desired_capabilities=desired_capabilities29# )3031# Navigate to the web page to be tested32driver.get('http://www.example.com/accessibility-testing')3334# Wait for the page to load35wait = WebDriverWait(driver, 10)36element = wait.until(EC.element_to_be_clickable((By.ID, 'content')))3738# Check if any content flashes more than three times39flashing_elements = driver.execute_script('''40 return [...document.querySelectorAll('*[class*=flash]')]41''')4243flashing_count = 044for flashing_element in flashing_elements:45 flashes = driver.execute_script('''46 return window.getComputedStyle(arguments[0])['animation-iteration-count']47 ''', flashing_element)48 if flashes == 'infinite':49 flashes = 9999999950 try:51 if int(flashes) > 3:52 flashing_count += 153 except ValueError:54 pass5556if flashing_count > 0:57 print('Test case failed: {count} content(s) flash more than three times'.format(count=flashing_count))58else:59 print('Test case passed')6061# Quit the browser62driver.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