首页 > 解决方案 > 验证 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;
    }

标签: seleniumselenium-webdriver

解决方案


而不是映射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;
    }

推荐阅读