selenium - 验证 web 元素中存在的属性标题
问题描述
我有一个关于网络元素列表的问题。我有一种方法可以验证 Web 元素列表中是否存在文本。我需要修改它以支持属性标题,并验证值是否存在。他们是否可以更改此方法以支持属性标题?
我的方法:
public Boolean isStringInWebElementsAttributeList(String expectedValue,List<WebElement> dropdownOptions) throws Exception {
Boolean isExists = dropdownOptions.stream().map(WebElement::getText).anyMatch(text -> expectedValue.equals(text));
return isExists;
}
解决方案
而不是映射getText
元素的title
属性。
public Boolean isStringInWebElementsAttributeList(String expectedValue,List<WebElement> dropdownOptions) throws Exception {
Boolean isExists = dropdownOptions.stream()
.map(el->el.getAttribute("title"))
.anyMatch(text -> expectedValue.equals(text));
return isExists;
}
推荐阅读
- security - 如何删除服务器标头 .NET Core Blazor 应用程序
- javascript - 如何将 Buffer.from() 与 crypto.timingSafeEqual() 一起使用?
- .net - C# 中的双精度魔法
- ios - SceneKit 节点的交集
- python - 根据字典在 csv 中搜索单词
- .net - 尝试在 Azure 管道 PATH ISSUE 上部署 SQL DB
- sql-server - 在sql的列中找出不包含特定值的字段
- javascript - 我想从数据库中获取图像路径并将其显示在反应组件中,我正在使用 require(),(错误:找不到模块)发生?
- javascript - 向下滚动时动画元素
- c# - 使用 Selenium C# 在私有模式下的 IE