All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.fluentlenium.core.filter.AttributeFilterPredicate Maven / Gradle / Ivy

package org.fluentlenium.core.filter;

import org.fluentlenium.core.domain.FluentWebElement;
import java.util.function.Predicate;

/**
 * Filter a FluentWebElement collection to return only the elements with the same text
 */
public class AttributeFilterPredicate implements Predicate {
    private final AttributeFilter filter;

    /**
     * Creates a new Attribute Filter Predicated, from an attribute filter
     *
     * @param filter attribute filter
     */
    AttributeFilterPredicate(AttributeFilter filter) {
        this.filter = filter;
    }

    @Override
    public boolean test(FluentWebElement element) {
        String attribute = getAttributeValue(element);
        return filter.getMatcher().isSatisfiedBy(attribute);
    }

    private String getAttributeValue(FluentWebElement element) {
        return "text".equalsIgnoreCase(filter.getAttribute()) ? element.text() : element.attribute(filter.getAttribute());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy