自动化 'keyboard Access' 以进行可访问性测试

Automating 'keyboard Access' for accessibility testing

在 Java 中使用 Selenium WebDriver,我试图自动化一个功能("Ensure that actionable elements are keyboard accessible"),我必须在其中完成所有交互元素(链接、单选按钮、复选框、按钮等) ) 在网页中按键盘键 'TAB'。它正在接受可访问性测试。我正在尝试从可访问性测试中自动执行 'keyboard access'。

请给我推荐 Selenium WebDriver 脚本

有很多方法可以做到这一点。您可以使用 sendkeys() 方法传递 KEYS.TAB 和其他可用的键选项。此外,您可以创建 Robot class 的对象并传递键盘选项。

使用 WebElement 的 sendkeys 方法需要 WebElement 将其发送到首先否定测试的类型。使用动作对象可能 work.So 我的脚本会类似于

static void goThroughTabs(){ WebDriver driver = new FirefoxDriver(); Actions action = new Actions(driver); int NumberOfElements = 10; //This is the number of elements to test for(int Counter = 0; Counter < NumberOfElements; Counter++){ action.sendKeys(Keys.TAB).build().perform(); } }

更大的问题是确保它在每个元素上都有标签,但对于这样的问题,我需要有关测试细节的更多信息。