忽略屏幕阅读器文本的宁静

时间:2019-10-11 16:32:16

标签: selenium testing automated-tests serenity-bdd cucumber-serenity

宁静会返回屏幕阅读器文本以及屏幕中的可见文本。如何获得用户可见的文本?

public static Target TransactionTypeOption = Target.the("Transaction Type options").located(By.xpath("//ipb-dropdown[@class='type-dropdown ']//li//div"));      
List<String> options = Text.of(TransactionTypeOption).viewedBy(actor).asList();

enter image description here

我已经将Bootstrap Sr-only类用于屏幕阅读器文本。 因此,我只想阅读第一个内容“所有交易”,但平静返回我“所有交易空白,当前选择”

1 个答案:

答案 0 :(得分:0)

您正在使用的XPath选择div,它还会在div(在本例中为, current selection)下拾取一些文本。我以前已经在Selenium中看到过这个问题,唯一的解决方案是处理代码中的多余文本。

public static Target TransactionTypeOption = Target.the("Transaction Type options").located(By.xpath("//ipb-dropdown[@class='type-dropdown ']//li//div"));

string textToFilterOut = driver.findElement(By.xpath("//span[@class='sr-only']")).getText();      
List<String> options = Text.of(TransactionTypeOption).replace(textToFilterOut, "").viewedBy(actor).asList();