Bastian
Bastian

Reputation: 1237

Validate attribute titles exists in web-elements

I have a question regarding list of web elements. I have a method that verify if text exists in list of web elements. I need to modify it to support attribute title, and validate if value exists. Is their a way to change this method to support attribute title?

My method:

public Boolean isStringInWebElementsAttributeList(String expectedValue,List<WebElement> dropdownOptions) throws Exception {
        Boolean  isExists = dropdownOptions.stream().map(WebElement::getText).anyMatch(text -> expectedValue.equals(text));
        return isExists;
    }

Upvotes: 0

Views: 50

Answers (1)

Madhan
Madhan

Reputation: 5818

Instead of mapping the getText map the element's title attribute.

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;
    }

Upvotes: 1

Related Questions