作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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();
我为屏幕阅读器文本使用了 bootstrap Sr-only 类。所以,我只想阅读第一个内容,即“所有交易”,但平静返回给我“所有交易空白,当前选择”
最佳答案
您正在使用的 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();
关于selenium - 平静地忽略屏幕阅读器文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58345284/
我是一名优秀的程序员,十分优秀!