宁静会返回屏幕阅读器文本以及屏幕中的可见文本。如何获得用户可见的文本?
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();
我已经将Bootstrap Sr-only类用于屏幕阅读器文本。 因此,我只想阅读第一个内容“所有交易”,但平静返回我“所有交易空白,当前选择”
答案 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();