gpt4 book ai didi

selenium - 平静地忽略屏幕阅读器文本

转载 作者:行者123 更新时间:2023-11-28 21:36:24 24 4
gpt4 key购买 nike

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 类。所以,我只想阅读第一个内容,即“所有交易”,但平静返回给我“所有交易空白,当前选择”

最佳答案

您正在使用的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com